ReaderType.java
上传用户:ycdfsj258
上传日期:2022-08-04
资源大小:1094k
文件大小:5k
源码类别:

图形图象

开发平台:

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) form;
  42.            System.out.println("servlet:"+request.getParameter("name"));
  43.            readerTypeForm.setName(readerTypeForm.getName());
  44.            int a=readerTypeDAO.insert(readerTypeForm);
  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("readerTypeAdd");
  53.         }
  54.        }
  55.        /***********************查询全部读者类型信息**************************/
  56.        private ActionForward readerTypeQuery(ActionMapping mapping, ActionForm form,
  57.                               HttpServletRequest request,
  58.                               HttpServletResponse response){
  59.        String str=null;
  60.        request.setAttribute("readerType",readerTypeDAO.query(str));
  61.        return mapping.findForward("readerTypeQuery");
  62.        }
  63.         /***********************查询修改读者类型信息**************************/
  64.         private ActionForward readerTypeModifyQuery(ActionMapping mapping, ActionForm form,
  65.                               HttpServletRequest request,
  66.                               HttpServletResponse response){
  67.             ReaderTypeForm readerTypeForm=(ReaderTypeForm)form;
  68.             readerTypeForm.setId(Integer.valueOf(request.getParameter("ID")));
  69.             request.setAttribute("readerTypeQueryif",readerTypeDAO.queryM(readerTypeForm));
  70.             return mapping.findForward("readerTypeQueryModify");
  71.         }
  72.         /***********************修改读者类型信息**************************/
  73.         private ActionForward readerTypeModify(ActionMapping mapping, ActionForm form,
  74.                               HttpServletRequest request,
  75.                               HttpServletResponse response){
  76.             ReaderTypeForm readerTypeForm=(ReaderTypeForm)form;
  77.             readerTypeForm.setName(readerTypeForm.getName());
  78.             readerTypeForm.setNumber(readerTypeForm.getNumber());
  79.             int ret=readerTypeDAO.update(readerTypeForm);
  80.             if(ret==0){
  81.                 request.setAttribute("error","修改读者类型信息失败!");
  82.                 return mapping.findForward("error");
  83.             }else{
  84.                 return mapping.findForward("readerTypeModify");
  85.             }
  86.         }
  87.         /***********************删除读者类型信息**************************/
  88.         private ActionForward readerTypeDel(ActionMapping mapping, ActionForm form,
  89.                               HttpServletRequest request,
  90.                               HttpServletResponse response){
  91.             ReaderTypeForm readerTypeForm=(ReaderTypeForm)form;
  92.             readerTypeForm.setId(Integer.valueOf(request.getParameter("ID")));
  93.             int ret=readerTypeDAO.delete(readerTypeForm);
  94.             if(ret==0){
  95.                 request.setAttribute("error","删除读者类型信息失败!");
  96.                 return mapping.findForward("error");
  97.             }else{
  98.                 return mapping.findForward("readerTypeDel");
  99.             }
  100.         }
  101. }