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