ReceiveMailShow.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:2k
源码类别:

WEB邮件程序

开发平台:

Java

  1. package com.softeem.webmail.receive;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import java.util.List;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import com.softeem.webmail.beans.receive.User;
  10. import com.softeem.webmail.dao.mail.Mail;
  11. import com.softeem.webmail.dao.mail.MailDAO;
  12. import com.softeem.webmail.tags.PageBean;
  13. public class ReceiveMailShow extends HttpServlet {
  14. public void doGet(HttpServletRequest request, HttpServletResponse response)
  15. throws ServletException, IOException {
  16. doPost(request, response);
  17. }
  18. public void doPost(HttpServletRequest request, HttpServletResponse response)
  19. throws ServletException, IOException {
  20. response.setContentType("text/html");
  21. User user=(User) request.getSession(false).getAttribute("user");
  22. String username=user.getUsername();
  23. List temp=null;
  24. String te=request.getParameter("page");
  25. List<Mail> mails=MailDAO.getMailsByUsername(username);
  26. int msize=mails.size();
  27. System.out.println(msize);
  28. if(te==null){
  29. PageBean pb=new PageBean(1,msize,10); 
  30. if(msize>10){
  31. temp=mails.subList(0, 10);
  32. }
  33. else{
  34. temp=mails.subList(0, msize);
  35. }
  36. request.setAttribute("pagebean", pb);
  37. }
  38. else{
  39. int page=Integer.parseInt(te);
  40. System.out.println(te+"<><><>");
  41. PageBean pb=new PageBean(page,mails.size(),10); 
  42. if(page*10<=pb.getTotal_count()&&(page-1)*10>=0){
  43. temp=mails.subList((page-1)*10, page*10);
  44. }
  45. else{
  46. if((page-1)*10>=0){
  47. temp=mails.subList((page-1)*10, pb.getTotal_count());
  48. }
  49. else{
  50. temp=mails.subList(0, pb.getTotal_count());
  51. }
  52. }
  53. request.setAttribute("pagebean", pb);
  54. }
  55. request.setAttribute("mailsinfo", temp);
  56. request.getRequestDispatcher("list.jsp").forward(request, response);
  57. }
  58. }