ReaderType.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.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.             return mapping.findForward("error");
  22.         }else if("readerTypeAdd".equals(action)){
  23.             return readerTypeAdd(mapping,form,request,response);
  24.         }else if("readerTypeQuery".equals(action)){
  25.             return readerTypeQuery(mapping,form,request,response);
  26.         }else if("readerTypeModifyQuery".equals(action)){
  27.             return readerTypeModifyQuery(mapping,form,request,response);
  28.         }else if("readerTypeModify".equals(action)){
  29.             return readerTypeModify(mapping,form,request,response);
  30.         }else if("readerTypeDel".equals(action)){
  31.             return readerTypeDel(mapping,form,request,response);
  32.         }
  33.         return mapping.findForward("error");
  34.     }
  35.     /***********************添加读者类型信息**************************/
  36.        private ActionForward readerTypeAdd(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse){
  37.            ReaderTypeForm readerTypeForm = (ReaderTypeForm) actionForm;
  38.            System.out.println("servlet:"+servletRequest.getParameter("name"));
  39.            readerTypeForm.setName(readerTypeForm.getName());
  40.            int a=readerTypeDAO.insert(readerTypeForm);
  41.            if(a==0){
  42.                servletRequest.setAttribute("error","读者类型信息添加失败!");
  43.                return actionMapping.findForward("error");
  44.          }else if(a==2){
  45.              servletRequest.setAttribute("error","该读者类型信息已经添加!");
  46.              return actionMapping.findForward("error");
  47.          }else{
  48.              return actionMapping.findForward("readerTypeAdd");
  49.         }
  50.        }
  51.        /***********************查询全部读者类型信息**************************/
  52.        private ActionForward readerTypeQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  53.        String str=null;
  54.        servletRequest.setAttribute("readerType",readerTypeDAO.query(str));
  55.        return actionMapping.findForward("readerTypeQuery");
  56.        }
  57.         /***********************查询修改读者类型信息**************************/
  58.         private ActionForward readerTypeModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  59.             ReaderTypeForm readerTypeForm=(ReaderTypeForm)actionForm;
  60.             readerTypeForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  61.             servletRequest.setAttribute("readerTypeQueryif",readerTypeDAO.queryM(readerTypeForm));
  62.             return actionMapping.findForward("readerTypeQueryModify");
  63.         }
  64.         /***********************修改读者类型信息**************************/
  65.         private ActionForward readerTypeModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  66.             ReaderTypeForm readerTypeForm=(ReaderTypeForm)actionForm;
  67.             readerTypeForm.setName(readerTypeForm.getName());
  68.             readerTypeForm.setNumber(readerTypeForm.getNumber());
  69.             int ret=readerTypeDAO.update(readerTypeForm);
  70.             if(ret==0){
  71.                 return actionMapping.findForward("error");
  72.             }else{
  73.                 return actionMapping.findForward("readerTypeModify");
  74.             }
  75.         }
  76.         /***********************删除读者类型信息**************************/
  77.         private ActionForward readerTypeDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  78.             ReaderTypeForm readerTypeForm=(ReaderTypeForm)actionForm;
  79.             readerTypeForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  80.             int ret=readerTypeDAO.delete(readerTypeForm);
  81.             if(ret==0){
  82.                 return actionMapping.findForward("error");
  83.             }else{
  84.                 return actionMapping.findForward("readerTypeDel");
  85.             }
  86.         }
  87. }