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

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