DraftboxServlet.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:2k
- package com.softeem.webmail.draftbox;
- import java.io.IOException;
- import java.util.List;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.softeem.webmail.beans.receive.User;
- import com.softeem.webmail.dao.draftbox.GetDraftboxInfo;
- import com.sun.java_cup.internal.internal_error;
- public class DraftboxServlet extends HttpServlet {
-
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doPost(request, response);
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- request.setCharacterEncoding("UTF-8");
- User user = (User) request.getSession(false).getAttribute("user");
- String username = user.getUsername();
- // String username="sad";
- String page = request.getParameter("page");
- List list = GetDraftboxInfo.getInfo(username);
- //拿到数据总条数
- int size = list.size();
- //定义一个i作为有多少页
- int i = 0;
- if(size%5==0){
- i = size/5;
- }else{
- i = size/5+1;
- }
- //定义一个List
- List draftbox = null;
- //当page==null时,即首次登陆此页面
- if(page==null){
- draftbox = GetDraftboxInfo.getResult(list, 1);
- request.setAttribute("currentpage", 1);
- }else{
- draftbox = GetDraftboxInfo.getResult(list, Integer.parseInt(page));
- request.setAttribute("currentpage", Integer.parseInt(page));
- }
-
- request.setAttribute("total", size);
- request.setAttribute("lastpage", i);
- request.setAttribute("draftbox", draftbox);
- request.getRequestDispatcher("draftbox.jsp").forward(request, response);
- }
-
- }