Reader.java~9~
上传用户: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 com.actionForm.ReaderForm;
  11. import java.util.Date;
  12. public class Reader extends Action {
  13.     private ReaderDAO readerDAO = null;
  14.     public Reader() {
  15.         this.readerDAO = new ReaderDAO();
  16.     }
  17.     public ActionForward perform(ActionMapping mapping, ActionForm form,
  18.                                  HttpServletRequest request,
  19.                                  HttpServletResponse response) {
  20.         String action =request.getParameter("action");
  21.         System.out.println("nreader*********************action="+action);
  22.         if(action==null||"".equals(action)){
  23.             request.setAttribute("error","您的操作有误!");
  24.             return mapping.findForward("error");
  25.         }else if("readerAdd".equals(action)){
  26.             return readerAdd(mapping,form,request,response);
  27.         }else if("readerQuery".equals(action)){
  28.             return readerQuery(mapping,form,request,response);
  29.         }else if("readerModifyQuery".equals(action)){
  30.             return readerModifyQuery(mapping,form,request,response);
  31.         }else if("readerModify".equals(action)){
  32.             return readerModify(mapping,form,request,response);
  33.         }else if("readerDel".equals(action)){
  34.             return readerDel(mapping,form,request,response);
  35.         }
  36.         request.setAttribute("error","操作失败!");
  37.         return mapping.findForward("error");
  38.     }
  39.     /***********************添加读者类型信息**************************/
  40.        private ActionForward readerAdd(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse){
  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 actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  71.        String str=null;
  72.        servletRequest.setAttribute("reader",readerDAO.query(str));
  73.        return actionMapping.findForward("readerQuery");
  74.        }
  75.         /***********************查询修改读者信息**************************/
  76.         private ActionForward readerModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  77.             ReaderForm readerForm=(ReaderForm)actionForm;
  78.             readerForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  79.             servletRequest.setAttribute("readerQueryif",readerDAO.queryM(readerForm));
  80.             return actionMapping.findForward("readerQueryModify");
  81.         }
  82.         /***********************修改读者信息**************************/
  83.         private ActionForward readerModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  84.             ReaderForm readerForm=(ReaderForm)actionForm;
  85.             readerForm.setName(readerForm.getName());
  86.             readerForm.setSex(readerForm.getSex());
  87.             readerForm.setBarcode(readerForm.getBarcode());
  88.             readerForm.setVocation(readerForm.getVocation());
  89.             readerForm.setBirthday(readerForm.getBirthday());
  90.             readerForm.setPaperType(readerForm.getPaperType());
  91.             readerForm.setPaperNO(readerForm.getPaperNO());
  92.             readerForm.setTel(readerForm.getTel());
  93.             readerForm.setEmail(readerForm.getEmail());
  94.             readerForm.setOperator(readerForm.getOperator());
  95.             readerForm.setRemark(readerForm.getRemark());
  96.             readerForm.setTypeid(readerForm.getTypeid());
  97.             int ret=readerDAO.update(readerForm);
  98.             if(ret==0){
  99.                 servletRequest.setAttribute("error","修改读者信息失败!");
  100.                 return actionMapping.findForward("error");
  101.             }else{
  102.                 return actionMapping.findForward("readerModify");
  103.             }
  104.         }
  105.         /***********************删除读者信息**************************/
  106.         private ActionForward readerDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  107.             ReaderForm readerForm=(ReaderForm)actionForm;
  108.             readerForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  109.             int ret=readerDAO.delete(readerForm);
  110.             if(ret==0){
  111.                 servletRequest.setAttribute("error","删除读者信息失败!");
  112.                 return actionMapping.findForward("error");
  113.             }else{
  114.                 return actionMapping.findForward("readerDel");
  115.             }
  116.         }
  117. }