BookCase.java~5~
上传用户: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 mapping, ActionForm form,
  37.                               HttpServletRequest request,
  38.                               HttpServletResponse response){
  39.         BookCaseForm bookCaseForm = (BookCaseForm) form;
  40.         System.out.println("servlet:"+request.getParameter("name"));
  41.         bookCaseForm.setName(bookCaseForm.getName());
  42.         int a=bookCaseDAO.insert(bookCaseForm);
  43.         if(a==0){
  44.             request.setAttribute("error","书架信息添加失败!");
  45.             return mapping.findForward("error");
  46.       }else if(a==2){
  47.           request.setAttribute("error","该书架信息已经添加!");
  48.           return mapping.findForward("error");
  49.       }else{
  50.           return mapping.findForward("bookcaseAdd");
  51.      }
  52.     }
  53.     /***********************查询全部书架信息**************************/
  54.     private ActionForward bookCaseQuery(ActionMapping mapping, ActionForm form,
  55.                               HttpServletRequest request,
  56.                               HttpServletResponse response){
  57.     String str=null;
  58.     request.setAttribute("bookcase",bookCaseDAO.query(str));
  59.     return mapping.findForward("bookcaseQuery");
  60.     }
  61.      /***********************查询修改书架信息**************************/
  62.      private ActionForward bookCaseModifyQuery(ActionMapping mapping, ActionForm form,
  63.                               HttpServletRequest request,
  64.                               HttpServletResponse response){
  65.          BookCaseForm bookCaseForm=(BookCaseForm)form;
  66.          bookCaseForm.setId(Integer.valueOf(request.getParameter("ID")));
  67.          request.setAttribute("bookCaseQueryif",bookCaseDAO.queryM(bookCaseForm));
  68.          return mapping.findForward("bookCaseQueryModify");
  69.      }
  70.      /***********************修改书架信息**************************/
  71.      private ActionForward bookCaseModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  72.          BookCaseForm bookCaseForm=(BookCaseForm)actionForm;
  73.          bookCaseForm.setName(servletRequest.getParameter("name"));
  74.          int ret=bookCaseDAO.update(bookCaseForm);
  75.          if(ret==0){
  76.              return actionMapping.findForward("error");
  77.          }else{
  78.              return actionMapping.findForward("bookCaseModify");
  79.          }
  80.      }
  81.      /***********************删除书架信息**************************/
  82.      private ActionForward bookCaseDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  83.          BookCaseForm bookCaseForm=(BookCaseForm)actionForm;
  84.          bookCaseForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  85.          int ret=bookCaseDAO.delete(bookCaseForm);
  86.          if(ret==0){
  87.              return actionMapping.findForward("error");
  88.          }else{
  89.              return actionMapping.findForward("bookCaseDel");
  90.          }
  91.      }
  92. }