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

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