Manager.java~103~
上传用户: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.         servletRequest.setAttribute("error","操作失败!");
  47.         return actionMapping.findForward("error");
  48.     }
  49.     //管理员身份验证
  50.     public ActionForward managerLogin(ActionMapping actionMapping,
  51.                                       ActionForm actionForm,
  52.                                       HttpServletRequest servletRequest,
  53.                                       HttpServletResponse servletResponse) {
  54.         ManagerForm managerForm = (ManagerForm) actionForm;
  55.         managerForm.setName(managerForm.getName());
  56.         managerForm.setPwd(managerForm.getPwd());
  57.         int ret = managerDAO.checkManager(managerForm);
  58.         System.out.print("验证结果ret的值:" + ret);
  59.         if (ret == 1) {
  60.             HttpSession session=servletRequest.getSession();
  61.             session.setAttribute("manager",managerForm.getName());
  62.             return actionMapping.findForward("managerLoginok");
  63.         } else {
  64.             servletRequest.setAttribute("error","您输入的管理员名称或密码错误!");
  65.             return actionMapping.findForward("error");
  66.         }
  67.     }
  68.     //查询管理员信息
  69.     private ActionForward managerQuery(ActionMapping actionMapping,
  70.                                        ActionForm actionForm,
  71.                                        HttpServletRequest servletRequest,
  72.                                        HttpServletResponse servletResponse) {
  73.         String str = null;
  74.         servletRequest.setAttribute("managerQuery", managerDAO.query(str));
  75.         return actionMapping.findForward("managerQuery");
  76.     }
  77.     //添加管理员信息
  78.     private ActionForward managerAdd(ActionMapping actionMapping,
  79.                                      ActionForm actionForm,
  80.                                      HttpServletRequest servletRequest,
  81.                                      HttpServletResponse servletResponse) {
  82.         ManagerForm managerForm = (ManagerForm) actionForm;
  83.         managerForm.setName(managerForm.getName());
  84.         managerForm.setPwd(managerForm.getPwd());
  85.         int ret = managerDAO.insert(managerForm);
  86.         System.out.println("返回值ret:"+ret);
  87.         if (ret == 1) {
  88.             return actionMapping.findForward("managerAdd");
  89.         } else if(ret==2){
  90.             servletRequest.setAttribute("error","该管理员信息已经添加!");
  91.             return actionMapping.findForward("error");
  92.         }else {
  93.             servletRequest.setAttribute("error","添加管理员信息失败!");
  94.             return actionMapping.findForward("error");
  95.         }
  96.     }
  97.     //查询修改管理员信息
  98.     private ActionForward managerModifyQuery(ActionMapping actionMapping,
  99.                                              ActionForm actionForm,
  100.                                              HttpServletRequest servletRequest,
  101.                                              HttpServletResponse
  102.                                              servletResponse) {
  103.         ManagerForm managerForm = (ManagerForm) actionForm;
  104.         managerForm.setId(Integer.valueOf(servletRequest.getParameter("id")));
  105.         System.out.print("查询到的id:"+servletRequest.getParameter("id"));
  106.         servletRequest.setAttribute("managerQueryif",
  107.                                     managerDAO.query_update(managerForm));
  108.         return actionMapping.findForward("managerQueryModify");
  109.     }
  110.     //修改密码时查询
  111.     private ActionForward pwdQuery(ActionMapping actionMapping,
  112.                                              ActionForm actionForm,
  113.                                              HttpServletRequest servletRequest,
  114.                                              HttpServletResponse
  115.                                              servletResponse) {
  116.         ManagerForm managerForm = (ManagerForm) actionForm;
  117.         HttpSession session=servletRequest.getSession();
  118.         String manager= (String) session.getAttribute("manager");
  119.         managerForm.setName(manager);
  120.         System.out.print("查询到的manager:"+manager);
  121.         servletRequest.setAttribute("pwdQueryif",
  122.                                     managerDAO.query_pwd(managerForm));
  123.         return actionMapping.findForward("pwdQueryModify");
  124.     }
  125.     //修改管理员信息
  126.     private ActionForward managerModify(ActionMapping actionMapping,
  127.                                         ActionForm actionForm,
  128.                                         HttpServletRequest servletRequest,
  129.                                         HttpServletResponse servletResponse) {
  130.         ManagerForm managerForm = (ManagerForm) actionForm;
  131.         managerForm.setId(managerForm.getId());
  132.         managerForm.setName(managerForm.getName());
  133.         managerForm.setPwd(managerForm.getPwd());
  134.         managerForm.setSysset(managerForm.getSysset());
  135.         managerForm.setReaderset(managerForm.getReaderset());
  136.         managerForm.setBookset(managerForm.getBookset());
  137.         managerForm.setBorrowback(managerForm.getBorrowback());
  138.         managerForm.setSysquery(managerForm.getSysquery());
  139.         int ret = managerDAO.update(managerForm);
  140.         if (ret == 0) {
  141.             servletRequest.setAttribute("error","修改管理员信息失败!");
  142.             return actionMapping.findForward("error");
  143.         } else {
  144.             return actionMapping.findForward("managerModify");
  145.         }
  146.     }
  147.     //删除管理员信息
  148.     private ActionForward managerDel(ActionMapping actionMapping,
  149.                                      ActionForm actionForm,
  150.                                      HttpServletRequest servletRequest,
  151.                                      HttpServletResponse servletResponse) {
  152.         ManagerForm managerForm = (ManagerForm) actionForm;
  153.         managerForm.setId(Integer.valueOf(servletRequest.getParameter("id")));
  154.         int ret = managerDAO.delete(managerForm);
  155.         if (ret == 0) {
  156.             servletRequest.setAttribute("error","删除管理员信息失败!");
  157.             return actionMapping.findForward("error");
  158.         } else {
  159.             return actionMapping.findForward("managerDel");
  160.         }
  161.     }
  162.     //修改管理员密码
  163.     private ActionForward modifypwd(ActionMapping actionMapping,
  164.                                      ActionForm actionForm,
  165.                                      HttpServletRequest servletRequest,
  166.                                      HttpServletResponse servletResponse){
  167.         ManagerForm managerForm=(ManagerForm) actionForm;
  168.         managerForm.setName(managerForm.getName());
  169.         managerForm.setPwd(managerForm.getPwd());
  170.         int ret=managerDAO.updatePwd(managerForm);
  171.         if(ret==0){
  172.             servletRequest.setAttribute("error","更改口令失败!");
  173.             return actionMapping.findForward("error");
  174.         }else{
  175.             return actionMapping.findForward("pwdModify");
  176.         }
  177.     }
  178. }