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

Jsp/Servlet

开发平台:

Java

  1. package com.action;
  2. import org.apache.struts.action.ActionMapping;
  3. import org.apache.struts.action.ActionForm;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.apache.struts.action.ActionForward;
  7. import com.actionForm.BookCaseForm;
  8. import org.apache.struts.action.Action;
  9. import com.dao.BookCaseDAO;
  10. public class BookCaseAdd extends Action {
  11.     private BookCaseDAO bookCaseDAO=null;
  12.     public BookCaseAdd(){
  13.         this.bookCaseDAO=new BookCaseDAO();
  14.     }
  15.     public ActionForward perform(ActionMapping actionMapping,
  16.                                  ActionForm actionForm,
  17.                                  HttpServletRequest servletRequest,
  18.                                  HttpServletResponse servletResponse) {
  19.     String action =servletRequest.getParameter("action");
  20.     System.out.println("nbookCase*********************action="+action);
  21.     if(action==null||"".equals(action)){
  22.         return actionMapping.findForward("error");
  23.     }else if("bookCaseAdd".equals(action)){
  24.         return bookCaseAdd(actionMapping,actionForm,servletRequest,servletResponse);
  25.     }else if("bookCaseQuery".equals(action)){
  26.         return bookCaseQuery(actionMapping,actionForm,servletRequest,servletResponse);
  27.     }else if("bookCaseModifyQuery".equals(action)){
  28.         return bookCaseModifyQuery(actionMapping,actionForm,servletRequest,servletResponse);
  29.     }else if("bookCaseModify".equals(action)){
  30.         return bookCaseModify(actionMapping,actionForm,servletRequest,servletResponse);
  31.     }else if("bookCaseDel".equals(action)){
  32.         return bookCaseDel(actionMapping,actionForm,servletRequest,servletResponse);
  33.     }
  34.     return actionMapping.findForward("error");
  35.     }
  36.  /***********************添加书架信息**************************/
  37.     private ActionForward bookCaseAdd(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse){
  38.         BookCaseForm bookCaseForm = (BookCaseForm) actionForm;
  39.         System.out.println("servlet:"+servletRequest.getParameter("name"));
  40.         bookCaseForm.setName(bookCaseForm.getName());
  41.         int a=bookCaseDAO.insert(bookCaseForm);
  42.         if(a==0){
  43.             servletRequest.setAttribute("error","书架信息添加失败!");
  44.             return actionMapping.findForward("error");
  45.       }else if(a==2){
  46.           servletRequest.setAttribute("error","该书架信息已经添加!");
  47.           return actionMapping.findForward("error");
  48.       }else{
  49.           return actionMapping.findForward("bookcaseAdd");
  50.      }
  51.     }
  52.     /***********************查询全部书架信息**************************/
  53.     private ActionForward bookCaseQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  54.     String str=null;
  55.     servletRequest.setAttribute("bookcase",bookCaseDAO.query(str));
  56.     return actionMapping.findForward("bookcaseQuery");
  57.     }
  58.      /***********************查询修改书架信息**************************/
  59.      private ActionForward bookCaseModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  60.          BookCaseForm bookCaseForm=(BookCaseForm)actionForm;
  61.          bookCaseForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  62.          servletRequest.setAttribute("bookCaseQueryif",bookCaseDAO.queryM(bookCaseForm));
  63.          return actionMapping.findForward("bookCaseQueryModify");
  64.      }
  65.      /***********************修改书架信息**************************/
  66.      private ActionForward bookCaseModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  67.          BookCaseForm bookCaseForm=(BookCaseForm)actionForm;
  68.          bookCaseForm.setName(servletRequest.getParameter("name"));
  69.          int ret=bookCaseDAO.update(bookCaseForm);
  70.          if(ret==0){
  71.              return actionMapping.findForward("error");
  72.          }else{
  73.              return actionMapping.findForward("bookCaseModify");
  74.          }
  75.      }
  76.      /***********************删除书架信息**************************/
  77.      private ActionForward bookCaseDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  78.          BookCaseForm bookCaseForm=(BookCaseForm)actionForm;
  79.          bookCaseForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  80.          int ret=bookCaseDAO.delete(bookCaseForm);
  81.          if(ret==0){
  82.              return actionMapping.findForward("error");
  83.          }else{
  84.              return actionMapping.findForward("bookCaseDel");
  85.          }
  86.      }
  87. }