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

WEB邮件程序

开发平台:

Java

  1. package com.softeem.webmail.draftbox;
  2. import java.io.IOException;
  3. import java.util.List;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.http.HttpServlet;
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;
  8. import com.softeem.webmail.beans.receive.User;
  9. import com.softeem.webmail.dao.draftbox.GetDraftboxInfo;
  10. import com.sun.java_cup.internal.internal_error;
  11. public class DraftboxServlet extends HttpServlet {
  12. public void doGet(HttpServletRequest request, HttpServletResponse response)
  13. throws ServletException, IOException {
  14.           doPost(request, response);
  15. }
  16. public void doPost(HttpServletRequest request, HttpServletResponse response)
  17. throws ServletException, IOException {
  18. response.setContentType("text/html;charset=UTF-8");
  19. request.setCharacterEncoding("UTF-8");
  20. User user = (User) request.getSession(false).getAttribute("user");
  21. String username = user.getUsername();
  22. // String username="sad";
  23. String page = request.getParameter("page");
  24. List list = GetDraftboxInfo.getInfo(username);
  25. //拿到数据总条数
  26. int size = list.size();
  27. //定义一个i作为有多少页
  28. int i = 0;
  29. if(size%5==0){
  30. i = size/5;
  31. }else{
  32. i = size/5+1;
  33. }
  34. //定义一个List
  35. List draftbox = null;
  36. //当page==null时,即首次登陆此页面
  37. if(page==null){
  38. draftbox = GetDraftboxInfo.getResult(list, 1);
  39. request.setAttribute("currentpage", 1);
  40. }else{
  41. draftbox = GetDraftboxInfo.getResult(list, Integer.parseInt(page));
  42. request.setAttribute("currentpage", Integer.parseInt(page));
  43. }
  44. request.setAttribute("total", size);
  45. request.setAttribute("lastpage", i);
  46. request.setAttribute("draftbox", draftbox);
  47. request.getRequestDispatcher("draftbox.jsp").forward(request, response);
  48. }
  49. }