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