——————————DescriptionStart——————————
运行环境 Java≥8、MySQL≥5.7、Tomcat≥8
开发工具 eclipse/idea/myeclipse/sts等均可配置运行
适用 课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的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项目:否;
技术栈
后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jQuery
使用说明
使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中config/db.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/xx登录
——————————CodeStart——————————
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 EmailDao dao=new EmailDao(); Email email=new Email(); try { email=dao.Findfile(id); } catch (SQLException e) { e.printStackTrace(); } File file = new File(email.getFilepath()); if (!file.exists()){ request.setCharacterEncoding("utf-8" ); } String realname=email.getFilename(); response.setHeader("content-disposition" , "attachment;filename=" + URLEncoder.encode(realname, "UTF-8" )); FileInputStream in = new FileInputStream(email.getFilepath()); OutputStream out = response.getOutputStream(); byte buffer[] = new byte [1024 ]; int len = 0 ; while ((len=in.read(buffer))>0 ){ out.write(buffer, 0 , len); } in.close(); out.close(); } public String findFileSavePathByFileName (String filename,String saveRootPath) { 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()){
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 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()) {
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 * time上传时间 * filename文件名 * savePath文件路径 * */ Date date = new Date(); DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm" ); time = format.format(date); String fileExtName = filename.substring(filename.lastIndexOf("." ) + 1 ); System.out.println("上传的文件的扩展名是:" + fileExtName); InputStream in = item.getInputStream(); saveFilename = makeFileName(title + "." + fileExtName); realSavePath = makePath(saveFilename, savePath); System.out.println(realSavePath + "\\" + saveFilename); FileOutputStream out = new FileOutputStream(realSavePath + "\\" + saveFilename); byte buffer[] = new byte [1024 ]; int len = 0 ; while ((len = in.read(buffer)) > 0 ) { out.write(buffer, 0 , len); } in.close(); out.close(); } } EmailDao fileDao = new EmailDao(); System.out.println("upload:" + email_content); Email email = new Email(userid, addresser_id, title, 0 , realSavePath + "\\" + saveFilename, time, email_content, filename);
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 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); if (!tmpFile.exists()) { tmpFile.mkdir(); } String message = "" ; try { DiskFileItemFactory factory = new DiskFileItemFactory(); 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) { } }); upload.setFileSizeMax(1024 * 1024 * 10 ); upload.setSizeMax(1024 * 1024 * 20 ); List<FileItem> list = upload.parseRequest(request); upload.setHeaderEncoding("UTF-8" ); for (FileItem item : list) { if (item.isFormField()) { String name = item.getFieldName();
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 public UploadHandleServlet () { super (); } protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 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); if (!tmpFile.exists()) { tmpFile.mkdir(); } String message = "" ; try { DiskFileItemFactory factory = new DiskFileItemFactory(); 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) { } });
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 FileOutputStream out = new FileOutputStream(realSavePath + "\\" + saveFilename); byte buffer[] = new byte [1024 ]; int len = 0 ; while ((len = in.read(buffer)) > 0 ) { out.write(buffer, 0 , len); } in.close(); out.close(); } } EmailDao fileDao = new EmailDao(); System.out.println("upload:" + email_content); Email email = new Email(userid, addresser_id, title, 0 , realSavePath + "\\" + saveFilename, time, email_content, filename); fileDao.UpFile(email, type); response.sendRedirect("/email_system/user/outbox.do" ); } catch (FileUploadBase.FileSizeLimitExceededException e) { e.printStackTrace(); request.setAttribute("message" , "单个文件超出最大值!!!" ); response.sendRedirect("/email_system/user/inbox.do" ); return ; } catch (FileUploadBase.SizeLimitExceededException e) { e.printStackTrace(); request.setAttribute("message" , "upload sizeover!!!" ); response.sendRedirect("/email_system/user/inbox.do" ); return ; } catch (Exception e) { request.setAttribute("message" , "upload error!!!" );
——————————PayStart——————————
项目链接: https://javayms.github.io?id=241122582008200vi https://javayms.pages.dev?id=241122582008200vi