当前位置:编程学习 > JSP >>

javamail通过pop3收信,附件下载,我的办法(代码!)

从附件名连接到这个servlet!
DownloadServlet.java
package MailServlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Socix</p>
* @author simon
* @version 1.0
*/
public class DownloadServlet extends HttpServlet
{
    public void service(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
    HttpSession session = request.getSession();
    String contentType = request.getParameter("contenttype");       //附件的ContentType
    int count = Integer.parseInt(request.getParameter("count"));    //第几个BodyPart
    Object body = session.getAttribute("body");                     //邮件的MimeMultipart
    if(body != null)
    {
System.out.println("download Start!");
        try
        {
            MimeMultipart mp        = (MimeMultipart)body;
            int i                   = mp.getCount();
补充:Jsp教程,邮件
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,