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

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