BookType.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.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 actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  65.             BookTypeForm bookTypeForm=(BookTypeForm)actionForm;
  66.             bookTypeForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  67.             servletRequest.setAttribute("bookTypeQueryif",bookTypeDAO.queryM(bookTypeForm));
  68.             return actionMapping.findForward("bookTypeQueryModify");
  69.         }
  70.         /***********************修改图书类型信息**************************/
  71.         private ActionForward bookTypeModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  72.             BookTypeForm bookTypeForm=(BookTypeForm)actionForm;
  73.             bookTypeForm.setTypeName(bookTypeForm.getTypeName());
  74.             bookTypeForm.setDays(bookTypeForm.getDays());
  75.             int ret=bookTypeDAO.update(bookTypeForm);
  76.             if(ret==0){
  77.                 servletRequest.setAttribute("error","修改图书类型信息失败!");
  78.                 return actionMapping.findForward("error");
  79.             }else{
  80.                 return actionMapping.findForward("bookTypeModify");
  81.             }
  82.         }
  83.         /***********************删除图书类型信息**************************/
  84.         private ActionForward bookTypeDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  85.             BookTypeForm bookTypeForm=(BookTypeForm)actionForm;
  86.             bookTypeForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  87.             int ret=bookTypeDAO.delete(bookTypeForm);
  88.             if(ret==0){
  89.                 servletRequest.setAttribute("error","删除图书类型信息失败!");
  90.                 return actionMapping.findForward("error");
  91.             }else{
  92.                 return actionMapping.findForward("bookTypeDel");
  93.             }
  94.         }
  95. }