BookCase.java
上传用户:ycdfsj258
上传日期:2022-08-04
资源大小:1094k
文件大小:5k
源码类别:

图形图象

开发平台:

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