Manager.java~103~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:9k
- package com.action;
- import org.apache.struts.action.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.actionForm.ManagerForm;
- import com.dao.ManagerDAO;
- import javax.servlet.http.HttpSession;
- public class Manager extends Action {
- private ManagerDAO managerDAO = null;
- public Manager() {
- this.managerDAO = new ManagerDAO();
- }
- public ActionForward perform(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- String action = servletRequest.getParameter("action");
- System.out.println("获取的查询字符串:" + action);
- if (action == null || "".equals(action)) {
- return actionMapping.findForward("error");
- }else if ("login".equals(action)) {
- return managerLogin(actionMapping, actionForm, servletRequest,
- servletResponse);
- } else if ("managerAdd".equals(action)) {
- return managerAdd(actionMapping, actionForm, servletRequest,
- servletResponse);
- } else if ("managerQuery".equals(action)) {
- return managerQuery(actionMapping, actionForm, servletRequest,
- servletResponse);
- } else if ("managerModifyQuery".equals(action)) {
- return managerModifyQuery(actionMapping, actionForm, servletRequest,
- servletResponse);
- } else if ("managerModify".equals(action)) {
- return managerModify(actionMapping, actionForm, servletRequest,
- servletResponse);
- } else if ("managerDel".equals(action)) {
- return managerDel(actionMapping, actionForm, servletRequest,
- servletResponse);
- }else if("querypwd".equals(action)){
- return pwdQuery(actionMapping, actionForm, servletRequest,
- servletResponse);
- }else if("modifypwd".equals(action)){
- return modifypwd(actionMapping, actionForm, servletRequest,
- servletResponse);
- }
- servletRequest.setAttribute("error","操作失败!");
- return actionMapping.findForward("error");
- }
- //管理员身份验证
- public ActionForward managerLogin(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- ManagerForm managerForm = (ManagerForm) actionForm;
- managerForm.setName(managerForm.getName());
- managerForm.setPwd(managerForm.getPwd());
- int ret = managerDAO.checkManager(managerForm);
- System.out.print("验证结果ret的值:" + ret);
- if (ret == 1) {
- HttpSession session=servletRequest.getSession();
- session.setAttribute("manager",managerForm.getName());
- return actionMapping.findForward("managerLoginok");
- } else {
- servletRequest.setAttribute("error","您输入的管理员名称或密码错误!");
- return actionMapping.findForward("error");
- }
- }
- //查询管理员信息
- private ActionForward managerQuery(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- String str = null;
- servletRequest.setAttribute("managerQuery", managerDAO.query(str));
- return actionMapping.findForward("managerQuery");
- }
- //添加管理员信息
- private ActionForward managerAdd(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- ManagerForm managerForm = (ManagerForm) actionForm;
- managerForm.setName(managerForm.getName());
- managerForm.setPwd(managerForm.getPwd());
- int ret = managerDAO.insert(managerForm);
- System.out.println("返回值ret:"+ret);
- if (ret == 1) {
- return actionMapping.findForward("managerAdd");
- } else if(ret==2){
- servletRequest.setAttribute("error","该管理员信息已经添加!");
- return actionMapping.findForward("error");
- }else {
- servletRequest.setAttribute("error","添加管理员信息失败!");
- return actionMapping.findForward("error");
- }
- }
- //查询修改管理员信息
- private ActionForward managerModifyQuery(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse
- servletResponse) {
- ManagerForm managerForm = (ManagerForm) actionForm;
- managerForm.setId(Integer.valueOf(servletRequest.getParameter("id")));
- System.out.print("查询到的id:"+servletRequest.getParameter("id"));
- servletRequest.setAttribute("managerQueryif",
- managerDAO.query_update(managerForm));
- return actionMapping.findForward("managerQueryModify");
- }
- //修改密码时查询
- private ActionForward pwdQuery(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse
- servletResponse) {
- ManagerForm managerForm = (ManagerForm) actionForm;
- HttpSession session=servletRequest.getSession();
- String manager= (String) session.getAttribute("manager");
- managerForm.setName(manager);
- System.out.print("查询到的manager:"+manager);
- servletRequest.setAttribute("pwdQueryif",
- managerDAO.query_pwd(managerForm));
- return actionMapping.findForward("pwdQueryModify");
- }
- //修改管理员信息
- private ActionForward managerModify(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- ManagerForm managerForm = (ManagerForm) actionForm;
- managerForm.setId(managerForm.getId());
- managerForm.setName(managerForm.getName());
- managerForm.setPwd(managerForm.getPwd());
- managerForm.setSysset(managerForm.getSysset());
- managerForm.setReaderset(managerForm.getReaderset());
- managerForm.setBookset(managerForm.getBookset());
- managerForm.setBorrowback(managerForm.getBorrowback());
- managerForm.setSysquery(managerForm.getSysquery());
- int ret = managerDAO.update(managerForm);
- if (ret == 0) {
- servletRequest.setAttribute("error","修改管理员信息失败!");
- return actionMapping.findForward("error");
- } else {
- return actionMapping.findForward("managerModify");
- }
- }
- //删除管理员信息
- private ActionForward managerDel(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- ManagerForm managerForm = (ManagerForm) actionForm;
- managerForm.setId(Integer.valueOf(servletRequest.getParameter("id")));
- int ret = managerDAO.delete(managerForm);
- if (ret == 0) {
- servletRequest.setAttribute("error","删除管理员信息失败!");
- return actionMapping.findForward("error");
- } else {
- return actionMapping.findForward("managerDel");
- }
- }
- //修改管理员密码
- private ActionForward modifypwd(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse){
- ManagerForm managerForm=(ManagerForm) actionForm;
- managerForm.setName(managerForm.getName());
- managerForm.setPwd(managerForm.getPwd());
- int ret=managerDAO.updatePwd(managerForm);
- if(ret==0){
- servletRequest.setAttribute("error","更改口令失败!");
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("pwdModify");
- }
- }
- }