Manager.java~97~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:9k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.action;
  2. import org.apache.struts.action.*;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import com.actionForm.ManagerForm;
  6. import com.dao.ManagerDAO;
  7. import javax.servlet.http.HttpSession;
  8. public class Manager extends Action {
  9.     private ManagerDAO managerDAO = null;
  10.     public Manager() {
  11.         this.managerDAO = new ManagerDAO();
  12.     }
  13.     public ActionForward perform(ActionMapping actionMapping,
  14.                                  ActionForm actionForm,
  15.                                  HttpServletRequest servletRequest,
  16.                                  HttpServletResponse servletResponse) {
  17.         String action = servletRequest.getParameter("action");
  18.         System.out.println("获取的查询字符串:" + action);
  19.         if (action == null || "".equals(action)) {
  20.             return actionMapping.findForward("error");
  21.         }else if ("login".equals(action)) {
  22.             return managerLogin(actionMapping, actionForm, servletRequest,
  23.                                 servletResponse);
  24.         } else if ("managerAdd".equals(action)) {
  25.             return managerAdd(actionMapping, actionForm, servletRequest,
  26.                               servletResponse);
  27.         } else if ("managerQuery".equals(action)) {
  28.             return managerQuery(actionMapping, actionForm, servletRequest,
  29.                                 servletResponse);
  30.         } else if ("managerModifyQuery".equals(action)) {
  31.             return managerModifyQuery(actionMapping, actionForm, servletRequest,
  32.                                       servletResponse);
  33.         } else if ("managerModify".equals(action)) {
  34.             return managerModify(actionMapping, actionForm, servletRequest,
  35.                                  servletResponse);
  36.         } else if ("managerDel".equals(action)) {
  37.             return managerDel(actionMapping, actionForm, servletRequest,
  38.                               servletResponse);
  39.         }else if("querypwd".equals(action)){
  40.                 return pwdQuery(actionMapping, actionForm, servletRequest,
  41.                               servletResponse);
  42.         }else if("modifypwd".equals(action)){
  43.             return modifypwd(actionMapping, actionForm, servletRequest,
  44.                               servletResponse);
  45.         }
  46.         return actionMapping.findForward("error");
  47.     }
  48.     //管理员身份验证
  49.     public ActionForward managerLogin(ActionMapping actionMapping,
  50.                                       ActionForm actionForm,
  51.                                       HttpServletRequest servletRequest,
  52.                                       HttpServletResponse servletResponse) {
  53.         ManagerForm managerForm = (ManagerForm) actionForm;
  54.         managerForm.setName(managerForm.getName());
  55.         managerForm.setPwd(managerForm.getPwd());
  56.         int ret = managerDAO.checkManager(managerForm);
  57.         System.out.print("验证结果ret的值:" + ret);
  58.         if (ret == 1) {
  59.             HttpSession session=servletRequest.getSession();
  60.             session.setAttribute("manager",managerForm.getName());
  61.             return actionMapping.findForward("managerLoginok");
  62.         } else {
  63.             return actionMapping.findForward("mangerLoginfilse");
  64.         }
  65.     }
  66.     //查询管理员信息
  67.     private ActionForward managerQuery(ActionMapping actionMapping,
  68.                                        ActionForm actionForm,
  69.                                        HttpServletRequest servletRequest,
  70.                                        HttpServletResponse servletResponse) {
  71.         String str = null;
  72.         servletRequest.setAttribute("managerQuery", managerDAO.query(str));
  73.         return actionMapping.findForward("managerQuery");
  74.     }
  75.     //添加管理员信息
  76.     private ActionForward managerAdd(ActionMapping actionMapping,
  77.                                      ActionForm actionForm,
  78.                                      HttpServletRequest servletRequest,
  79.                                      HttpServletResponse servletResponse) {
  80.         ManagerForm managerForm = (ManagerForm) actionForm;
  81.         managerForm.setName(managerForm.getName());
  82.         managerForm.setPwd(managerForm.getPwd());
  83.         int ret = managerDAO.insert(managerForm);
  84.         System.out.println("返回值ret:"+ret);
  85.         if (ret == 1) {
  86.             return actionMapping.findForward("managerAdd");
  87.         } else if(ret==2){
  88.             servletRequest.setAttribute("error","该管理员信息已经添加!");
  89.             return actionMapping.findForward("error");
  90.         }else {
  91.             servletRequest.setAttribute("error","添加管理员信息失败!");
  92.             return actionMapping.findForward("error");
  93.         }
  94.     }
  95.     //查询修改管理员信息
  96.     private ActionForward managerModifyQuery(ActionMapping actionMapping,
  97.                                              ActionForm actionForm,
  98.                                              HttpServletRequest servletRequest,
  99.                                              HttpServletResponse
  100.                                              servletResponse) {
  101.         ManagerForm managerForm = (ManagerForm) actionForm;
  102.         managerForm.setId(Integer.valueOf(servletRequest.getParameter("id")));
  103.         System.out.print("查询到的id:"+servletRequest.getParameter("id"));
  104.         servletRequest.setAttribute("managerQueryif",
  105.                                     managerDAO.query_update(managerForm));
  106.         return actionMapping.findForward("managerQueryModify");
  107.     }
  108.     //修改密码时查询
  109.     private ActionForward pwdQuery(ActionMapping actionMapping,
  110.                                              ActionForm actionForm,
  111.                                              HttpServletRequest servletRequest,
  112.                                              HttpServletResponse
  113.                                              servletResponse) {
  114.         ManagerForm managerForm = (ManagerForm) actionForm;
  115.         HttpSession session=servletRequest.getSession();
  116.         String manager= (String) session.getAttribute("manager");
  117.         managerForm.setName(manager);
  118.         System.out.print("查询到的manager:"+manager);
  119.         servletRequest.setAttribute("pwdQueryif",
  120.                                     managerDAO.query_update(managerForm));
  121.         return actionMapping.findForward("pwdQueryModify");
  122.     }
  123.     //修改管理员信息
  124.     private ActionForward managerModify(ActionMapping actionMapping,
  125.                                         ActionForm actionForm,
  126.                                         HttpServletRequest servletRequest,
  127.                                         HttpServletResponse servletResponse) {
  128.         ManagerForm managerForm = (ManagerForm) actionForm;
  129.         managerForm.setId(managerForm.getId());
  130.         managerForm.setName(managerForm.getName());
  131.         managerForm.setPwd(managerForm.getPwd());
  132.         managerForm.setSysset(managerForm.getSysset());
  133.         managerForm.setReaderset(managerForm.getReaderset());
  134.         managerForm.setBookset(managerForm.getBookset());
  135.         managerForm.setBorrowback(managerForm.getBorrowback());
  136.         managerForm.setSysquery(managerForm.getSysquery());
  137.         int ret = managerDAO.update(managerForm);
  138.         if (ret == 0) {
  139.             return actionMapping.findForward("error");
  140.         } else {
  141.             return actionMapping.findForward("managerModify");
  142.         }
  143.     }
  144.     //删除管理员信息
  145.     private ActionForward managerDel(ActionMapping actionMapping,
  146.                                      ActionForm actionForm,
  147.                                      HttpServletRequest servletRequest,
  148.                                      HttpServletResponse servletResponse) {
  149.         ManagerForm managerForm = (ManagerForm) actionForm;
  150.         managerForm.setId(Integer.valueOf(servletRequest.getParameter("id")));
  151.         int ret = managerDAO.delete(managerForm);
  152.         if (ret == 0) {
  153.             return actionMapping.findForward("error");
  154.         } else {
  155.             return actionMapping.findForward("managerDel");
  156.         }
  157.     }
  158.     //修改管理员密码
  159.     private ActionForward modifypwd(ActionMapping actionMapping,
  160.                                      ActionForm actionForm,
  161.                                      HttpServletRequest servletRequest,
  162.                                      HttpServletResponse servletResponse){
  163.         ManagerForm managerForm=(ManagerForm) actionForm;
  164.         managerForm.setName(managerForm.getName());
  165.         managerForm.setPwd(managerForm.getPwd());
  166.         int ret=managerDAO.update(managerForm);
  167.         if(ret==0){
  168.             servletRequest.setAttribute("error","更改口令失败!");
  169.             return actionMapping.findForward("error");
  170.         }else{
  171.             return actionMapping.findForward("pwdModify");
  172.         }
  173.     }
  174. }