BookCase.java~8~
上传用户: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 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 mapping, ActionForm form,
  72.                               HttpServletRequest request,
  73.                               HttpServletResponse response){
  74.          BookCaseForm bookCaseForm=(BookCaseForm)form;
  75.          bookCaseForm.setName(request.getParameter("name"));
  76.          int ret=bookCaseDAO.update(bookCaseForm);
  77.          if(ret==0){
  78.              request.setAttribute("error","修改书架信息失败!");
  79.              return mapping.findForward("error");
  80.          }else{
  81.              return mapping.findForward("bookCaseModify");
  82.          }
  83.      }
  84.      /***********************删除书架信息**************************/
  85.      private ActionForward bookCaseDel(ActionMapping mapping, ActionForm form,
  86.                               HttpServletRequest request,
  87.                               HttpServletResponse response
  88. ){
  89.          BookCaseForm bookCaseForm=(BookCaseForm)form;
  90.          bookCaseForm.setId(Integer.valueOf(request.getParameter("ID")));
  91.          int ret=bookCaseDAO.delete(bookCaseForm);
  92.          if(ret==0){
  93.              request.setAttribute("error","删除书架信息失败!");
  94.              return mapping.findForward("error");
  95.          }else{
  96.              return mapping.findForward("bookCaseDel");
  97.          }
  98.      }
  99. }