求救:學習用JAVAMAIL編的郵件系統出問題了!
//登陸
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>
[<%=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 + "  ");
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 + "  ");
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 + "  ");
}
}
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>
我想請教的問題是:listfolder.jsp中第7行"String msg=request.getParameter("msg");中的這"msg"以及detail.jsp中的
if(null == request.getParameter("part"))中的“part"從何而來??
請各位老師賜教!我感激不盡!
相關文章
- 求救:JAVAMAIL編的EMAIL系統JavaAI
- Java郵件(JavaMail)JavaAI
- postfix郵件系統之郵件客戶端無法收郵件問題解析客戶端
- javamail郵件傳送例子JavaAI
- 使用JavaMail傳送郵件JavaAI
- javamail傳送郵件(轉)JavaAI
- 求救。我編的一個整數階乘的程式出問題了。急!
- 系統出問題了
- 傳送郵件出現問題
- 請教:如何解決JAVAMAIL傳送html格式郵件時的亂碼問題JavaAIHTML
- 郵件開發:Javamail、JAF簡介JavaAI
- JavaMail郵件傳送在linux環境下不能傳送的問題解決JavaAILinux
- JSP與JavaMail(6)---編寫靈活的郵件傳送程式 (轉)JSJavaAI
- 使用JavaMail實現收取和回覆郵件JavaAI
- JavaMail(JAVA郵件服務) API詳解JavaAIAPI
- 請問 javamail 傳送程式編譯問題JavaAI編譯
- 用javamail顯示覆合郵件的內容的親身體會 (轉)JavaAI
- JavaMail:java使用QQ郵箱傳送郵件簡單版。JavaAI
- 請高手幫忙了,關於javamail的問題JavaAI
- JavaMail傳送郵件時常見錯誤JavaAI
- swoole 郵件系統
- laravel傳送啟用郵件的思路和問題Laravel
- JavaMail 保證郵件傳送成功的方法總結JavaAI
- iOS12系統應用傳送普通郵件構建郵件iOS
- windows10系統匯出outlook郵件的方法Windows
- JavaMail學習筆記(四)、使用POP3協議接收並解析電子郵件(全)JavaAI筆記協議
- Springboot+Javamail實現郵件傳送Spring BootJavaAI
- 【知識積累】JavaMail實現發郵件功能JavaAI
- 關於 JavaMail 的問題JavaAI
- 彭先生,javaMail的問題JavaAI
- javamail的問題急急急JavaAI
- javamail的標記問題JavaAI
- JSP與JavaMail(4)---傳送HTML格式的郵件 (轉)JSJavaAIHTML
- 上午同事的求救郵件,有關監聽的異常!
- 企業郵件系統
- Java郵件(問題解決)Java
- Jboss3.0-Tomcat4.03下運用JavaMail發電子郵件. (轉)S3TomcatJavaAI
- 關於郵件監控的問題