Reader.java~12~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:6k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import com.actionForm.ReaderForm;
  5. import org.apache.struts.action.*;
  6. import com.dao.ReaderDAO;
  7. import java.util.Date;
  8. public class Reader extends Action {
  9.     private ReaderDAO readerDAO = null;
  10.     public Reader() {
  11.         this.readerDAO = new ReaderDAO();
  12.     }
  13.     public ActionForward perform(ActionMapping mapping, ActionForm form,
  14.                                  HttpServletRequest request,
  15.                                  HttpServletResponse response) {
  16.         String action =request.getParameter("action");
  17.         System.out.println("nreader*********************action="+action);
  18.         if(action==null||"".equals(action)){
  19.             request.setAttribute("error","您的操作有误!");
  20.             return mapping.findForward("error");
  21.         }else if("readerAdd".equals(action)){
  22.             return readerAdd(mapping,form,request,response);
  23.         }else if("readerQuery".equals(action)){
  24.             return readerQuery(mapping,form,request,response);
  25.         }else if("readerModifyQuery".equals(action)){
  26.             return readerModifyQuery(mapping,form,request,response);
  27.         }else if("readerModify".equals(action)){
  28.             return readerModify(mapping,form,request,response);
  29.         }else if("readerDel".equals(action)){
  30.             return readerDel(mapping,form,request,response);
  31.         }
  32.         request.setAttribute("error","操作失败!");
  33.         return mapping.findForward("error");
  34.     }
  35.     /***********************添加读者类型信息**************************/
  36.        private ActionForward readerAdd(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse){
  37.            ReaderForm readerForm = (ReaderForm) actionForm;
  38.            readerForm.setName(readerForm.getName());
  39.            readerForm.setSex(readerForm.getSex());
  40.            readerForm.setBarcode(readerForm.getBarcode());
  41.            readerForm.setVocation(readerForm.getVocation());
  42.            readerForm.setBirthday(readerForm.getBirthday());
  43.            readerForm.setPaperType(readerForm.getPaperType());
  44.            readerForm.setPaperNO(readerForm.getPaperNO());
  45.            readerForm.setTel(readerForm.getTel());
  46.            readerForm.setEmail(readerForm.getEmail());
  47.            //获取系统日期
  48.            Date date1=new Date();
  49.            java.sql.Date date=new java.sql.Date(date1.getTime());
  50.            readerForm.setCreateDate(date.toString());
  51.            readerForm.setOperator(readerForm.getOperator());
  52.            readerForm.setRemark(readerForm.getRemark());
  53.            readerForm.setTypeid(readerForm.getTypeid());
  54.            int a=readerDAO.insert(readerForm);
  55.            if(a==0){
  56.                servletRequest.setAttribute("error","读者信息添加失败!");
  57.                return actionMapping.findForward("error");
  58.          }else if(a==2){
  59.              servletRequest.setAttribute("error","该读者信息已经添加!");
  60.              return actionMapping.findForward("error");
  61.          }else{
  62.              return actionMapping.findForward("readerAdd");
  63.         }
  64.        }
  65.        /***********************查询全部读者信息**************************/
  66.        private ActionForward readerQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  67.        String str=null;
  68.        servletRequest.setAttribute("reader",readerDAO.query(str));
  69.        return actionMapping.findForward("readerQuery");
  70.        }
  71.         /***********************查询修改读者信息**************************/
  72.         private ActionForward readerModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  73.             ReaderForm readerForm=(ReaderForm)actionForm;
  74.             readerForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  75.             servletRequest.setAttribute("readerQueryif",readerDAO.queryM(readerForm));
  76.             return actionMapping.findForward("readerQueryModify");
  77.         }
  78.         /***********************修改读者信息**************************/
  79.         private ActionForward readerModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  80.             ReaderForm readerForm=(ReaderForm)actionForm;
  81.             readerForm.setName(readerForm.getName());
  82.             readerForm.setSex(readerForm.getSex());
  83.             readerForm.setBarcode(readerForm.getBarcode());
  84.             readerForm.setVocation(readerForm.getVocation());
  85.             readerForm.setBirthday(readerForm.getBirthday());
  86.             readerForm.setPaperType(readerForm.getPaperType());
  87.             readerForm.setPaperNO(readerForm.getPaperNO());
  88.             readerForm.setTel(readerForm.getTel());
  89.             readerForm.setEmail(readerForm.getEmail());
  90.             readerForm.setOperator(readerForm.getOperator());
  91.             readerForm.setRemark(readerForm.getRemark());
  92.             readerForm.setTypeid(readerForm.getTypeid());
  93.             int ret=readerDAO.update(readerForm);
  94.             if(ret==0){
  95.                 servletRequest.setAttribute("error","修改读者信息失败!");
  96.                 return actionMapping.findForward("error");
  97.             }else{
  98.                 return actionMapping.findForward("readerModify");
  99.             }
  100.         }
  101.         /***********************删除读者信息**************************/
  102.         private ActionForward readerDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  103.             ReaderForm readerForm=(ReaderForm)actionForm;
  104.             readerForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  105.             int ret=readerDAO.delete(readerForm);
  106.             if(ret==0){
  107.                 servletRequest.setAttribute("error","删除读者信息失败!");
  108.                 return actionMapping.findForward("error");
  109.             }else{
  110.                 return actionMapping.findForward("readerDel");
  111.             }
  112.         }
  113. }