当前位置:   article > 正文

基于javaweb+mysql的ssm邮箱邮件收发管理系统(java+ssm+jsp+jq+mysql)_java邮件管理系统

java邮件管理系统

基于javaweb+mysql的ssm邮箱邮件收发管理系统(java+ssm+jsp+jq+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SSM邮箱邮件收发管理系统(java+ssm+jsp+jq+mysql)

项目介绍

本项目为基于SSM的邮件收发管理系统;

用户角色包含以下功能: 用户登录,写信给好友,查看收件箱,查看已发送的邮件,草稿箱查看,通讯录设置,个人资料管理等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;

技术栈

  1. 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jQuery

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中config/db.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/xx登录
                email.setTile(rs.getString("friend_name"));
                emails.add(email);
            }

        }
        request.setAttribute("friends", emails);
        request.getRequestDispatcher("../friend.jsp").forward(request, response);
        return "inbox";
    }
}
package servlets;
 
 

 
/**
 * Servlet implementation class ImgDown
 */
@WebServlet("/downloadFile")
public class FileDown extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /*
     * @see HttpServlet#HttpServlet()
     */
    public FileDown() {
        super();
        // TODO Auto-generated constructor stub
    }
 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if(request.getParameter("id")!=null){
			System.out.println(request.getParameter("id"));
		}else{
			System.out.println("!!");
		}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
                } else {
                    return "login";
                }
            }

        }
        return "login";
    }

    @RequestMapping(value = "/inbox.do")
    public String inbox(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            String sql = "select * from email where addresser_id='" + userid + "'";
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
                emails.add(email);
            }

        }

        request.setAttribute("in_emails", emails);
        request.getRequestDispatcher("../inbox.jsp").forward(request, response);
        return "inbox";
    }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
        try {
            //创建一个DiskFileItemFactory工厂
            DiskFileItemFactory factory = new DiskFileItemFactory();
            //设置缓冲区的大小为1000KB,如果不指定,那么缓冲区的大小默认是10KB
            factory.setSizeThreshold(1024 * 100);
            //设置上传时生成的临时文件的保存目录
            factory.setRepository(tmpFile);
            //创建一个文件上传解析器
            ServletFileUpload upload = new ServletFileUpload(factory);
            //监听文件上传进度
            upload.setProgressListener(new ProgressListener() {
                public void update(long pBytesRead, long pContentLength, int arg2) {
                    //System.out.println("文件大小为:" + pContentLength + ",当前已处理:" + pBytesRead);
                }
            });

            //设置上传单个文件的大小的最大值,目前是设置为1024*1024字节,也就是1MB
            upload.setFileSizeMax(1024 * 1024 * 10);
            //设置上传文件总量的最大值,最大值=同时上传的多个文件的大小的最大值的和,目前设置为10MB
            upload.setSizeMax(1024 * 1024 * 20);
            //4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
            List<FileItem> list = upload.parseRequest(request);
            upload.setHeaderEncoding("UTF-8");
            for (FileItem item : list) {
                //如果fileitem中封装的是普通输入项的数据
                if (item.isFormField()) {
                    String name = item.getFieldName();
                    //解决普通输入项的数据的中文乱码问题
                    String value = item.getString("UTF-8");
                    //value = new String(value.getBytes("iso8859-1"),"UTF-8");
                    System.out.println(name + "=" + value);
                    if (name.equals("userid")) {
                        userid = value;
                    }
                    if (name.equals("title")) {
                        title = value;
                    }
                    if (name.equals("receiver")) {
                        addresser_id = value;
                    }
                    if (name.equals("email_content")) {
                        email_content = value;
                    }
                } else {
                    //得到上传的文件名称,
                    filename = item.getName();
                    System.out.println(filename);
                    if (filename == null || filename.trim().equals("")) {

                    }
                    //解决上传文件名的中文乱码
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
                Email email = new Email();
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
                emails.add(email);
            }

        }

        request.setAttribute("out_emails", emails);
        request.getRequestDispatcher("../outbox.jsp").forward(request, response);
        return "outbox";
    }

    @RequestMapping(value = "/save.do")
    public String save(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            String sql = "select * from save where addressee_id='" + userid + "'";
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
                emails.add(email);
            }

        }

        request.setAttribute("save_emails", emails);
        request.getRequestDispatcher("../save.jsp").forward(request, response);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
                }
            }

        }
        return "login";
    }

    @RequestMapping(value = "/inbox.do")
    public String inbox(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            String sql = "select * from email where addresser_id='" + userid + "'";
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
                emails.add(email);
            }

        }

        request.setAttribute("in_emails", emails);
        request.getRequestDispatcher("../inbox.jsp").forward(request, response);
        return "inbox";
    }

    @RequestMapping(value = "/outbox.do")
    public String outbox(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            String sql = "select * from email where addressee_id='" + userid + "'";
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53

/**
 * user/list.do
 * user/add.do
 *
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @RequestMapping(value = "/register.do")
    public String register(String userid, String password, String username, HttpServletRequest request) throws SQLException {
        String sql = "insert into `user` (`userid`,`password`,`username`) values(?,?,?)";
        try {
            DBConnection dao = new DBConnection();
            Connection c = dao.getConnection();
            PreparedStatement ps = c.prepareStatement(sql);
            ps.setString(1, userid);
            ps.setString(2, password);
            ps.setString(3, username);
            ps.execute();
            ps.close();
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "login";
    }

    @RequestMapping(value = "/login.do")
    public String login(String userid, String password, HttpServletRequest request) throws SQLException {
        if (userid != null && password != null && !userid.equals("") && !password.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            String sql = "select * from user where userid='" + userid + "'";
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            String username = "";
            while (rs.next()) {
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
        File tmpFile = new File(tempPath);
        //如果临时文件不存在,创建临时目录e
        if (!tmpFile.exists()) {
            tmpFile.mkdir();
        }
        String message = "";
        try {
            //创建一个DiskFileItemFactory工厂
            DiskFileItemFactory factory = new DiskFileItemFactory();
            //设置缓冲区的大小为1000KB,如果不指定,那么缓冲区的大小默认是10KB
            factory.setSizeThreshold(1024 * 100);
            //设置上传时生成的临时文件的保存目录
            factory.setRepository(tmpFile);
            //创建一个文件上传解析器
            ServletFileUpload upload = new ServletFileUpload(factory);
            //监听文件上传进度
            upload.setProgressListener(new ProgressListener() {
                public void update(long pBytesRead, long pContentLength, int arg2) {
                    //System.out.println("文件大小为:" + pContentLength + ",当前已处理:" + pBytesRead);
                }
            });

            //设置上传单个文件的大小的最大值,目前是设置为1024*1024字节,也就是1MB
            upload.setFileSizeMax(1024 * 1024 * 10);
            //设置上传文件总量的最大值,最大值=同时上传的多个文件的大小的最大值的和,目前设置为10MB
            upload.setSizeMax(1024 * 1024 * 20);
            //4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
            List<FileItem> list = upload.parseRequest(request);
            upload.setHeaderEncoding("UTF-8");
            for (FileItem item : list) {
                //如果fileitem中封装的是普通输入项的数据
                if (item.isFormField()) {
                    String name = item.getFieldName();
                    //解决普通输入项的数据的中文乱码问题
                    String value = item.getString("UTF-8");
                    //value = new String(value.getBytes("iso8859-1"),"UTF-8");
                    System.out.println(name + "=" + value);
                    if (name.equals("userid")) {
                        userid = value;
                    }
                    if (name.equals("title")) {
                        title = value;
                    }
                    if (name.equals("receiver")) {
                        addresser_id = value;
                    }
                    if (name.equals("email_content")) {
                        email_content = value;
                    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

/**
 * user/list.do
 * user/add.do
 *
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @RequestMapping(value = "/register.do")
    public String register(String userid, String password, String username, HttpServletRequest request) throws SQLException {
        String sql = "insert into `user` (`userid`,`password`,`username`) values(?,?,?)";
        try {
            DBConnection dao = new DBConnection();
            Connection c = dao.getConnection();
            PreparedStatement ps = c.prepareStatement(sql);
            ps.setString(1, userid);
            ps.setString(2, password);
            ps.setString(3, username);
            ps.execute();
            ps.close();
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            String sql = "select * from save where addressee_id='" + userid + "'";
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
                emails.add(email);
            }

        }

        request.setAttribute("save_emails", emails);
        request.getRequestDispatcher("../save.jsp").forward(request, response);
        return "save";
    }

    @RequestMapping(value = "/sinbox.do")
    public String s_inbox(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        String title = request.getParameter("stitle");
        String addressee_id = request.getParameter("addressee_id");
        String readed = request.getParameter("readed");
        String sql = "select * from email where addresser_id='" + userid + "'";
        if (title != null && !title.trim().equals("")) {
            sql = sql + " and title like'%" + title + "%'";
        }
        if (addressee_id != null && !addressee_id.trim().equals("")) {
            sql = sql + " and addressee_id like '%" + addressee_id + "%'";
        }
        if (readed != null && !readed.trim().equals("")) {
            sql = sql + " and readed='" + readed + "'";
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

    @RequestMapping(value = "/login.do")
    public String login(String userid, String password, HttpServletRequest request) throws SQLException {
        if (userid != null && password != null && !userid.equals("") && !password.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            String sql = "select * from user where userid='" + userid + "'";
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            String username = "";
            while (rs.next()) {
                if (rs.getString("password").equals(password)) {
                    username = rs.getString("username");
                    HttpSession session = request.getSession();
                    session.setAttribute("userid", userid);
                    session.setAttribute("username", username);
                    return "main";
                } else {
                    return "login";
                }
            }

        }
        return "login";
    }

    @RequestMapping(value = "/inbox.do")
    public String inbox(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            String sql = "select * from email where addresser_id='" + userid + "'";
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
                emails.add(email);
            }

        }

        request.setAttribute("save_emails", emails);
        request.getRequestDispatcher("../save.jsp").forward(request, response);
        return "save";
    }

    @RequestMapping(value = "/sinbox.do")
    public String s_inbox(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        String title = request.getParameter("stitle");
        String addressee_id = request.getParameter("addressee_id");
        String readed = request.getParameter("readed");
        String sql = "select * from email where addresser_id='" + userid + "'";
        if (title != null && !title.trim().equals("")) {
            sql = sql + " and title like'%" + title + "%'";
        }
        if (addressee_id != null && !addressee_id.trim().equals("")) {
            sql = sql + " and addressee_id like '%" + addressee_id + "%'";
        }
        if (readed != null && !readed.trim().equals("")) {
            sql = sql + " and readed='" + readed + "'";
        }
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
                emails.add(email);
            }

        }

        request.setAttribute("in_emails", emails);
        request.getRequestDispatcher("../inbox.jsp").forward(request, response);
        return "inbox";
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
        }
        return "login";
    }

    @RequestMapping(value = "/inbox.do")
    public String inbox(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            String sql = "select * from email where addresser_id='" + userid + "'";
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
                emails.add(email);
            }

        }

        request.setAttribute("in_emails", emails);
        request.getRequestDispatcher("../inbox.jsp").forward(request, response);
        return "inbox";
    }

    @RequestMapping(value = "/outbox.do")
    public String outbox(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
                emails.add(email);
            }

        }

        request.setAttribute("in_emails", emails);
        request.getRequestDispatcher("../inbox.jsp").forward(request, response);
        return "inbox";
    }

    @RequestMapping(value = "/friend.do")
    public String friend(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        String sql = "select * from friend where userid='" + userid + "'";
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setAddressee_id(rs.getString("friend_id"));
                email.setTile(rs.getString("friend_name"));
                emails.add(email);
            }

        }
        request.setAttribute("friends", emails);
        request.getRequestDispatcher("../friend.jsp").forward(request, response);
        return "inbox";
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
                emails.add(email);
            }

        }

        request.setAttribute("out_emails", emails);
        request.getRequestDispatcher("../outbox.jsp").forward(request, response);
        return "outbox";
    }

    @RequestMapping(value = "/save.do")
    public String save(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            String sql = "select * from save where addressee_id='" + userid + "'";
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setId(rs.getInt("id"));
                email.setAddressee_id(rs.getString("addressee_id"));
                email.setAddresser_id(rs.getString("addresser_id"));
                email.setReaded(rs.getInt("readed"));
                email.setTile(rs.getString("title"));
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
                email.setTime(rs.getString("time"));
                if (rs.getString("filepath") != null) {
                    email.setFilepath(rs.getString("filepath"));
                    ;
                }
                emails.add(email);
            }

        }

        request.setAttribute("in_emails", emails);
        request.getRequestDispatcher("../inbox.jsp").forward(request, response);
        return "inbox";
    }

    @RequestMapping(value = "/friend.do")
    public String friend(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session = request.getSession();
        String userid = session.getAttribute("userid").toString();
        String sql = "select * from friend where userid='" + userid + "'";
        List<Email> emails = new ArrayList<>();
        if (userid != null && !userid.equals("")) {
            DBConnection dao = new DBConnection();
            Connection conn = dao.getConnection();
            PreparedStatement ptmt = conn.prepareStatement(sql);
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                Email email = new Email();
                email.setAddressee_id(rs.getString("friend_id"));
                email.setTile(rs.getString("friend_name"));
                emails.add(email);
            }

        }
        request.setAttribute("friends", emails);
        request.getRequestDispatcher("../friend.jsp").forward(request, response);
        return "inbox";
    }
}
package servlets;
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
         *2String savePath = this.getServletContext().getInitParameter("AttFilePath");
         */
        //得到上传文件的保存目录
        //String savePath = this.getServletContext().getRealPath("/WEB-INF/upload");
        //得到上传文件的保存目录
        String tempPath = this.getServletContext().getRealPath("/WEB-INF/temp");
        String title = "";
        String addresser_id = "";
        String email_content = "";
        String userid = "";
        String savePath = "D:\\email_system\\upload";
        String saveFilename = "";
        String realSavePath = "";
        String time = "";
        String filename = "";
        String type = request.getParameter("type");
        File tmpFile = new File(tempPath);
        //如果临时文件不存在,创建临时目录e
        if (!tmpFile.exists()) {
            tmpFile.mkdir();
        }
        String message = "";
        try {
            //创建一个DiskFileItemFactory工厂
            DiskFileItemFactory factory = new DiskFileItemFactory();
            //设置缓冲区的大小为1000KB,如果不指定,那么缓冲区的大小默认是10KB
            factory.setSizeThreshold(1024 * 100);
            //设置上传时生成的临时文件的保存目录
            factory.setRepository(tmpFile);
            //创建一个文件上传解析器
            ServletFileUpload upload = new ServletFileUpload(factory);
            //监听文件上传进度
            upload.setProgressListener(new ProgressListener() {
                public void update(long pBytesRead, long pContentLength, int arg2) {
                    //System.out.println("文件大小为:" + pContentLength + ",当前已处理:" + pBytesRead);
                }
            });

            //设置上传单个文件的大小的最大值,目前是设置为1024*1024字节,也就是1MB
            upload.setFileSizeMax(1024 * 1024 * 10);
            //设置上传文件总量的最大值,最大值=同时上传的多个文件的大小的最大值的和,目前设置为10MB
            upload.setSizeMax(1024 * 1024 * 20);
            //4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
            List<FileItem> list = upload.parseRequest(request);
            upload.setHeaderEncoding("UTF-8");
            for (FileItem item : list) {
                //如果fileitem中封装的是普通输入项的数据
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
    	//用日期得到文件名的
    	Calendar date=Calendar.getInstance();		 
 		SimpleDateFormat format1=new SimpleDateFormat( "yyyy-MM-dd"); 
 		String name=format1.format(date.getTime());
 		String dir = saveRootPath + "\\" + name;
 		File file=new File(dir);
 		//如果目录不存在
        if(!file.exists()){
            //创建目录
            file.mkdirs();
        }
        return dir;
    }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
package com.controller;

@Controller
@RequestMapping("/email")
public class EmailController {
	@RequestMapping(value="/inbox.do")
	public String inbox(HttpServletRequest request) throws SQLException{
		HttpSession session = request.getSession();  
		String userid=session.getAttribute("userid").toString();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/967631
推荐阅读
相关标签
  

闽ICP备14008679号