求救:JAVAMAIL編的EMAIL系統
我是一名剛開始學習JAVAMAIL程式設計的新手,我照一本教科書上的做了個郵件系統,主要在接收帶有附件的郵件時出了問題,原始碼如下:
我想請教的問題是:listfolder.jsp中第7行"String msg=request.getParameter("msg");中的這"msg"以及detail.jsp中的
if(null == request.getParameter("part"))中的“part"從何而來??
請各位老師賜教!我感激不盡!
//登陸 login.html <HEAD> <TITLE>MyMail</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </HEAD> <BODY> <FORM Name="FM" ACTION="login.jsp" METHOD="POST"> <table width="55%" border="1" align="center"><tr> <td width="37%">郵件主機名:</td> <td width="63%"><INPUT NAME="host"></td> </tr><tr> <td width="37%">使用者名稱:</td> <td width="63%"><INPUT NAME="user"></td> </tr><tr> <td width="37%">密碼o</td> <td width="63%"><input type="password" name="password"></td> </tr> <tr><td colspan=2 align="center"><a href="javascript:FM.submit();">提交</a> </td></tr> </table> </FORM> </BODY></HTML> login.jsp <% session.setAttribute("host",request.getParameter("host")); session.setAttribute("user",request.getParameter("user")); session.setAttribute("password",request.getParameter("password")); response.sendRedirect("listfolder.jsp?action=list"); %> //顯示郵件列表的JSP頁面 listfolder.jsp <HTML><HEAD><TITLE>網路收件箱</TITLE> <%@ page import=" javax.mail.*,java.util.*" contentType="text/html;charset=GB2312"%> </head><body> <% String action=request.getParameter("action"); String msg=request.getParameter("msg"); if (action==null) { response.sendRedirect("login.html"); }else if (action.equals("logout")){ response.sendRedirect("login.html"); }else{ // Get a Properties object Properties props = System.getProperties(); // Get a Session object Session foldersession = Session.getDefaultInstance(props, null); foldersession.setDebug(true); URLName urln = new URLName("pop3://"+session.getAttribute("user")+":" +session.getAttribute("password")+"@"+session.getAttribute("host")+"/"); Store store = foldersession.getStore(urln); store.connect(); Folder inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_WRITE); if (action.equals("delete")){ if (msg!=null){ int imsg=Integer.parseInt(msg); Message message = inbox.getMessage(imsg); if(message != null){ message.setFlag(Flags.Flag.DELETED,true); inbox.close(true); } } store.close(); out.print("刪除成功<br>"); out.print("<A HREF=\"listfolder.jsp?action=list\">返回收件箱</A>"); }else if (action.equals("list")){ int count = inbox.getMessageCount(); %> <A HREF="listfolder.jsp?action=list">收件箱</A> <A HREF="listfolder.jsp?action=logout" >退出</A> <% for(int i = 1;i <= count;i++){ Message message = inbox.getMessage(i); if(!message.isSet(Flags.Flag.DELETED)) { String title = message.getSubject(); String title2 = new String(title.getBytes("iso8859-1"), "gb2312"); %> <form> <p class="indent">[<%=i%>]<A HREF="detail.jsp?msg=<%=i%>">標題:<%=title2%></A> <A HREF="listfolder.jsp?action=delete&msg=<%=i%>">刪除</a> </form> <% } } inbox.close(true); store.close(); } } %> </BODY></HTML> //接收帶有附件的Email detail.jsp <HTML><HEAD><TITLE>網路收件箱</TITLE> <%@ page import=" javax.mail.*,java.util.*,java.io.*" contentType="text/html;charset=GB2312"%> </head><body> <A HREF="listfolder.jsp?action=list">收件箱</A> <A HREF="listfolder.jsp?action=logout" >退出</A> <% String msg=request.getParameter("msg"); // Get a Properties object Properties props = System.getProperties(); // Get a Session object Session foldersession = Session.getDefaultInstance(props, null); foldersession.setDebug(true); URLName urln = new URLName("pop3://"+session.getAttribute("user")+":" +session.getAttribute("password")+"@"+session.getAttribute("host")+"/"); Store store = foldersession.getStore(urln); store.connect(); Folder inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_WRITE); if (msg!=null){ int imsg=Integer.parseInt(msg); Message message = inbox.getMessage(imsg); Address[] addresses; %> <table width=80% align="center"> <tr><td>發件人:</td><td> <% addresses=message.getFrom(); if(addresses != null) for(int i = 0;i < addresses.length;i++) out.print(addresses[i] + "  "); else out.println("無"); %> </td></tr> <tr><td>收件人:</td><td> <% addresses=message.getRecipients(Message.RecipientType.TO); if(addresses != null) for(int i = 0;i < addresses.length;i++) out.print(addresses[i] + "  "); else out.println("無"); %> </td></tr> <tr><td>抄送:</td><td> <% addresses=message.getRecipients(Message.RecipientType.CC); if(addresses != null) { for(int i = 0;i < addresses.length;i++) { out.print(addresses[i] + "  "); } } else { out.println("無"); } String title = message.getSubject(); String title2 = new String(title.getBytes("iso8859-1"), "gb2312"); %> </td></tr> <tr><td>標題:</td><td><%=title2%></td></tr> <tr><td colspan=2> <% if(null == request.getParameter("part")){ if(message.isMimeType("multipart/*")){ Multipart multipart = (Multipart)message.getContent(); for(int i = 0;i < multipart.getCount();i++){ Part p = multipart.getBodyPart(i); String disposition = p.getDisposition(); if ((disposition != null) && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))) { String filename = p.getFileName(); %> <br><A HREF="detail.jsp?msg=<%=message.getMessageNumber()%>&part=<%=i%>">附件</A> <% }else if (disposition==null){ if (p.isMimeType("text/plain")) { out.print(p.getContent()); }else { //特殊附件 } } } } else if(message.isMimeType("text/plain")) { out.print(message.getContent()); } } else { int partnr = Integer.parseInt(request.getParameter("part")); Part p; if(partnr < 0) p = message; else{ Multipart multipart = (Multipart)message.getContent(); p = multipart.getBodyPart(partnr); } response.setContentType(p.getContentType()); if (p.getFileName()!=null){ response.setHeader("Content-Disposition", "attachment; filename=\"" + p.getFileName() + "\""); } OutputStream os = response.getOutputStream(); InputStream is = p.getInputStream(); int c = is.read(); while(c != -1) { os.write(c); c = is.read(); } } %> </td></tr> </table> <% } inbox.close(true); store.close(); %> </BODY></HTML> <p class="indent"> |
我想請教的問題是:listfolder.jsp中第7行"String msg=request.getParameter("msg");中的這"msg"以及detail.jsp中的
if(null == request.getParameter("part"))中的“part"從何而來??
請各位老師賜教!我感激不盡!
相關文章
- 求救:學習用JAVAMAIL編的郵件系統出問題了!JavaAI
- 怎樣在APPLET中發EMAIL javamail (轉)APPAIJava
- HTML Email的編寫HTMLAI
- HTML Email 編寫指南HTMLAI
- Socket打造高效能伺服器的求救!求救!求救!伺服器
- 版主求救:Jbuilder編譯Jsp出錯UI編譯JS
- 請問 javamail 傳送程式編譯問題JavaAI編譯
- javamailJavaAI
- 用PHP編寫email群發器 (轉)PHPAI
- JSP與JavaMail(1)---JavaMail和JAF的介紹 (轉)JSJavaAI
- Apple iwach系統升級:watchOS 3 還可以求救?APP
- javaMail【Z】JavaAI
- javamail參考JavaAI
- Docker自建Email伺服器-已購域名上私人郵件系統DockerAI伺服器
- JSP與JavaMail(6)---編寫靈活的郵件傳送程式 (轉)JSJavaAI
- 關於 JavaMail 的問題JavaAI
- 彭先生,javaMail的問題JavaAI
- javamail的問題急急急JavaAI
- javamail的標記問題JavaAI
- 編譯系統概要編譯
- 編譯系統核心編譯
- ORACLE EBS系統中的編譯Oracle編譯
- 求救。我編的一個整數階乘的程式出問題了。急!
- Java郵件(JavaMail)JavaAI
- JavaMail 傳送附件的例子 (轉)JavaAI
- 求救:Tomcat中jsp檔案不停地被編譯TomcatJS編譯
- 系統中沒有郵件客戶端設定autoLink=email會掛掉的問題客戶端AI
- JavaMail中文附件的處理方法 (轉)JavaAI
- 如何更改註冊的emailAI
- 關於javamail亂碼?JavaAI
- Sugarcrm Email IntegrationAI
- Delphi發emailAI
- 資訊系統中的編碼問題
- Linux系統中的Vim編輯器Linux
- 求救 關於parallel的問題Parallel
- (七)系統通用元件編寫元件
- Kubernetes 編排系統
- 編譯最小linux系統編譯Linux