BookType.java
上传用户: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.BookTypeForm;
  8. import org.apache.struts.action.Action;
  9. import com.dao.BookTypeDAO;
  10. public class BookType extends Action {
  11.     private BookTypeDAO bookTypeDAO = null;
  12.     public BookType() {
  13.         this.bookTypeDAO = new BookTypeDAO();
  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("nbookType*********************action="+action);
  20.         if(action==null||"".equals(action)){
  21.             request.setAttribute("error","您的操作有误!");
  22.             return mapping.findForward("error");
  23.         }else if("bookTypeAdd".equals(action)){
  24.             return bookTypeAdd(mapping,form,request,response);
  25.         }else if("bookTypeQuery".equals(action)){
  26.             return bookTypeQuery(mapping,form,request,response);
  27.         }else if("bookTypeModifyQuery".equals(action)){
  28.             return bookTypeModifyQuery(mapping,form,request,response);
  29.         }else if("bookTypeModify".equals(action)){
  30.             return bookTypeModify(mapping,form,request,response);
  31.         }else if("bookTypeDel".equals(action)){
  32.             return bookTypeDel(mapping,form,request,response);
  33.         }
  34.         request.setAttribute("error","操作失败!");
  35.         return mapping.findForward("error");
  36.     }
  37.     /***********************添加图书类型信息**************************/
  38.     private ActionForward bookTypeAdd(ActionMapping mapping, ActionForm form,
  39.                            HttpServletRequest request,
  40.                            HttpServletResponse response){
  41.            BookTypeForm bookTypeForm = (BookTypeForm) form;
  42.            System.out.println("servlet:"+bookTypeForm.getTypeName());
  43.            bookTypeForm.setTypeName(bookTypeForm.getTypeName());
  44.            int a=bookTypeDAO.insert(bookTypeForm);
  45.            if(a==0){
  46.                request.setAttribute("error","图书类型信息添加失败!");
  47.                return mapping.findForward("error");
  48.          }else if(a==2){
  49.              request.setAttribute("error","该图书类型信息已经添加!");
  50.              return mapping.findForward("error");
  51.          }else{
  52.              return mapping.findForward("bookTypeAdd");
  53.         }
  54.        }
  55.        /***********************查询全部图书类型信息**************************/
  56.        private ActionForward bookTypeQuery(ActionMapping mapping, ActionForm form,
  57.                               HttpServletRequest request,
  58.                               HttpServletResponse response){
  59.        String str=null;
  60.        request.setAttribute("bookType",bookTypeDAO.query(str));
  61.        return mapping.findForward("bookTypeQuery");
  62.        }
  63.         /***********************查询修改图书类型信息**************************/
  64.         private ActionForward bookTypeModifyQuery(ActionMapping mapping, ActionForm form,
  65.                               HttpServletRequest request,
  66.                               HttpServletResponse response){
  67.             BookTypeForm bookTypeForm=(BookTypeForm)form;
  68.             bookTypeForm.setId(Integer.valueOf(request.getParameter("ID")));
  69.             request.setAttribute("bookTypeQueryif",bookTypeDAO.queryM(bookTypeForm));
  70.             return mapping.findForward("bookTypeQueryModify");
  71.         }
  72.         /***********************修改图书类型信息**************************/
  73.         private ActionForward bookTypeModify(ActionMapping mapping, ActionForm form,
  74.                               HttpServletRequest request,
  75.                               HttpServletResponse response){
  76.             BookTypeForm bookTypeForm=(BookTypeForm)form;
  77.             bookTypeForm.setTypeName(bookTypeForm.getTypeName());
  78.             bookTypeForm.setDays(bookTypeForm.getDays());
  79.             int ret=bookTypeDAO.update(bookTypeForm);
  80.             if(ret==0){
  81.                 request.setAttribute("error","修改图书类型信息失败!");
  82.                 return mapping.findForward("error");
  83.             }else{
  84.                 return mapping.findForward("bookTypeModify");
  85.             }
  86.         }
  87.         /***********************删除图书类型信息**************************/
  88.         private ActionForward bookTypeDel(ActionMapping mapping, ActionForm form,
  89.                               HttpServletRequest request,
  90.                               HttpServletResponse response){
  91.             BookTypeForm bookTypeForm=(BookTypeForm)form;
  92.             bookTypeForm.setId(Integer.valueOf(request.getParameter("ID")));
  93.             int ret=bookTypeDAO.delete(bookTypeForm);
  94.             if(ret==0){
  95.                 request.setAttribute("error","删除图书类型信息失败!");
  96.                 return mapping.findForward("error");
  97.             }else{
  98.                 return mapping.findForward("bookTypeDel");
  99.             }
  100.         }
  101. }