BookType.java~5~
上传用户: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 actionMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse){
  39.            BookTypeForm bookTypeForm = (BookTypeForm) actionForm;
  40.            System.out.println("servlet:"+bookTypeForm.getTypeName());
  41.            bookTypeForm.setTypeName(bookTypeForm.getTypeName());
  42.            int a=bookTypeDAO.insert(bookTypeForm);
  43.            if(a==0){
  44.                servletRequest.setAttribute("error","图书类型信息添加失败!");
  45.                return actionMapping.findForward("error");
  46.          }else if(a==2){
  47.              servletRequest.setAttribute("error","该图书类型信息已经添加!");
  48.              return actionMapping.findForward("error");
  49.          }else{
  50.              return actionMapping.findForward("bookTypeAdd");
  51.         }
  52.        }
  53.        /***********************查询全部图书类型信息**************************/
  54.        private ActionForward bookTypeQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  55.        String str=null;
  56.        servletRequest.setAttribute("bookTypeQueryif",bookTypeDAO.query(str));
  57.        return actionMapping.findForward("bookTypeQuery");
  58.        }
  59.         /***********************查询修改图书类型信息**************************/
  60.         private ActionForward bookTypeModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  61.             BookTypeForm bookTypeForm=(BookTypeForm)actionForm;
  62.             bookTypeForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  63.             servletRequest.setAttribute("bookTypeQueryif",bookTypeDAO.queryM(bookTypeForm));
  64.             return actionMapping.findForward("bookTypeQueryModify");
  65.         }
  66.         /***********************修改图书类型信息**************************/
  67.         private ActionForward bookTypeModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  68.             BookTypeForm bookTypeForm=(BookTypeForm)actionForm;
  69.             bookTypeForm.setTypeName(bookTypeForm.getTypeName());
  70.             bookTypeForm.setDays(bookTypeForm.getDays());
  71.             int ret=bookTypeDAO.update(bookTypeForm);
  72.             if(ret==0){
  73.                 servletRequest.setAttribute("error","修改图书类型信息失败!");
  74.                 return actionMapping.findForward("error");
  75.             }else{
  76.                 return actionMapping.findForward("bookTypeModify");
  77.             }
  78.         }
  79.         /***********************删除图书类型信息**************************/
  80.         private ActionForward bookTypeDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  81.             BookTypeForm bookTypeForm=(BookTypeForm)actionForm;
  82.             bookTypeForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  83.             int ret=bookTypeDAO.delete(bookTypeForm);
  84.             if(ret==0){
  85.                 servletRequest.setAttribute("error","删除图书类型信息失败!");
  86.                 return actionMapping.findForward("error");
  87.             }else{
  88.                 return actionMapping.findForward("bookTypeDel");
  89.             }
  90.         }
  91. }