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

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.         }else if("readerDetail".equals(action)){
  32.             return readerDetail(mapping,form,request,response);
  33.         }
  34.         request.setAttribute("error","操作失败!");
  35.         return mapping.findForward("error");
  36.     }
  37.     /***********************添加读者信息**************************/
  38.     private ActionForward readerAdd(ActionMapping mapping, ActionForm form,
  39.                            HttpServletRequest request,
  40.                            HttpServletResponse response){
  41.            ReaderForm readerForm = (ReaderForm) actionForm;
  42.            readerForm.setName(readerForm.getName());
  43.            readerForm.setSex(readerForm.getSex());
  44.            readerForm.setBarcode(readerForm.getBarcode());
  45.            readerForm.setVocation(readerForm.getVocation());
  46.            readerForm.setBirthday(readerForm.getBirthday());
  47.            readerForm.setPaperType(readerForm.getPaperType());
  48.            readerForm.setPaperNO(readerForm.getPaperNO());
  49.            readerForm.setTel(readerForm.getTel());
  50.            readerForm.setEmail(readerForm.getEmail());
  51.            //获取系统日期
  52.            Date date1=new Date();
  53.            java.sql.Date date=new java.sql.Date(date1.getTime());
  54.            readerForm.setCreateDate(date.toString());
  55.            readerForm.setOperator(readerForm.getOperator());
  56.            readerForm.setRemark(readerForm.getRemark());
  57.            readerForm.setTypeid(readerForm.getTypeid());
  58.            int a=readerDAO.insert(readerForm);
  59.            if(a==0){
  60.                servletRequest.setAttribute("error","读者信息添加失败!");
  61.                return actionMapping.findForward("error");
  62.          }else if(a==2){
  63.              servletRequest.setAttribute("error","该读者信息已经添加!");
  64.              return actionMapping.findForward("error");
  65.          }else{
  66.              return actionMapping.findForward("readerAdd");
  67.         }
  68.        }
  69.        /***********************查询全部读者信息**************************/
  70.        private ActionForward readerQuery(ActionMapping mapping, ActionForm form,
  71.                               HttpServletRequest request,
  72.                               HttpServletResponse response){
  73.        String str=null;
  74.        servletRequest.setAttribute("reader",readerDAO.query(str));
  75.        return actionMapping.findForward("readerQuery");
  76.        }
  77.         /***********************查询修改读者信息**************************/
  78.         private ActionForward readerModifyQuery(ActionMapping mapping, ActionForm form,
  79.                               HttpServletRequest request,
  80.                               HttpServletResponse response){
  81.             ReaderForm readerForm=(ReaderForm)actionForm;
  82.             System.out.println("查询修改读者信息:"+servletRequest.getParameter("ID"));
  83.             readerForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  84.             servletRequest.setAttribute("readerQueryif",readerDAO.queryM(readerForm));
  85.             return actionMapping.findForward("readerQueryModify");
  86.         }
  87.         /***********************查询读者详细信息**************************/
  88.         private ActionForward readerDetail(ActionMapping mapping, ActionForm form,
  89.                               HttpServletRequest request,
  90.                               HttpServletResponse response){
  91.             ReaderForm readerForm=(ReaderForm)actionForm;
  92.             readerForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  93.             servletRequest.setAttribute("readerDetail",readerDAO.queryM(readerForm));
  94.             return actionMapping.findForward("readerDeatil");
  95.         }
  96.         /***********************修改读者信息**************************/
  97.         private ActionForward readerModify(ActionMapping mapping, ActionForm form,
  98.                               HttpServletRequest request,
  99.                               HttpServletResponse response){
  100.             ReaderForm readerForm=(ReaderForm)actionForm;
  101.             readerForm.setName(readerForm.getName());
  102.             readerForm.setSex(readerForm.getSex());
  103.             readerForm.setBarcode(readerForm.getBarcode());
  104.             readerForm.setVocation(readerForm.getVocation());
  105.             readerForm.setBirthday(readerForm.getBirthday());
  106.             readerForm.setPaperType(readerForm.getPaperType());
  107.             readerForm.setPaperNO(readerForm.getPaperNO());
  108.             readerForm.setTel(readerForm.getTel());
  109.             readerForm.setEmail(readerForm.getEmail());
  110.             readerForm.setOperator(readerForm.getOperator());
  111.             readerForm.setRemark(readerForm.getRemark());
  112.             readerForm.setTypeid(readerForm.getTypeid());
  113.             int ret=readerDAO.update(readerForm);
  114.             if(ret==0){
  115.                 servletRequest.setAttribute("error","修改读者信息失败!");
  116.                 return actionMapping.findForward("error");
  117.             }else{
  118.                 return actionMapping.findForward("readerModify");
  119.             }
  120.         }
  121.         /***********************删除读者信息**************************/
  122.         private ActionForward readerDel(ActionMapping mapping, ActionForm form,
  123.                               HttpServletRequest request,
  124.                               HttpServletResponse response){
  125.             ReaderForm readerForm=(ReaderForm)actionForm;
  126.             readerForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  127.             int ret=readerDAO.delete(readerForm);
  128.             if(ret==0){
  129.                 servletRequest.setAttribute("error","删除读者信息失败!");
  130.                 return actionMapping.findForward("error");
  131.             }else{
  132.                 return actionMapping.findForward("readerDel");
  133.             }
  134.         }
  135. }