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

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.BookForm;
  8. import org.apache.struts.action.Action;
  9. import com.dao.BookDAO;
  10. import java.util.Date;
  11. public class Book extends Action {
  12.     private BookDAO bookDAO = null;
  13.     public Book() {
  14.         this.bookDAO = new BookDAO();
  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("nbook*********************action="+action);
  21.         if(action==null||"".equals(action)){
  22.             request.setAttribute("error","您的操作有误!");
  23.             return mapping.findForward("error");
  24.         }else if("bookAdd".equals(action)){
  25.             return bookAdd(mapping,form,request,response);
  26.         }else if("bookQuery".equals(action)){
  27.             return bookQuery(mapping,form,request,response);
  28.         }else if("bookModifyQuery".equals(action)){
  29.             return bookModifyQuery(mapping,form,request,response);
  30.         }else if("bookModify".equals(action)){
  31.             return bookModify(mapping,form,request,response);
  32.         }else if("bookDel".equals(action)){
  33.             return bookDel(mapping,form,request,response);
  34.         }else if("bookDetail".equals(action)){
  35.             return bookDetail(mapping,form,request,response);
  36.         }else if("bookifQuery".equals(action)){
  37.             return bookifQuery(mapping,form,request,response);
  38.         }
  39.         request.setAttribute("error","操作失败!");
  40.         return mapping.findForward("error");
  41.     }
  42.     /***********************添加图书信息**************************/
  43.        private ActionForward bookAdd(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse){
  44.            BookForm bookForm = (BookForm) actionForm;
  45.            bookForm.setBarcode(bookForm.getBarcode());
  46.            bookForm.setBookName(bookForm.getBookName());
  47.            bookForm.setTypeId(bookForm.getTypeId());
  48.            bookForm.setAuthor(bookForm.getAuthor());
  49.            bookForm.setTranslator(bookForm.getTranslator());
  50.            bookForm.setIsbn(bookForm.getIsbn());
  51.            bookForm.setPrice(bookForm.getPrice());
  52.            bookForm.setPage(bookForm.getPage());
  53.            bookForm.setBookcaseid(bookForm.getBookcaseid());
  54.            bookForm.setStorage(bookForm.getStorage());
  55.            //获取系统日期
  56.            Date date1=new Date();
  57.            java.sql.Date date=new java.sql.Date(date1.getTime());
  58.            bookForm.setInTime(date.toString());
  59.            bookForm.setOperator(bookForm.getOperator());
  60.            int a=bookDAO.insert(bookForm);
  61.            if(a==0){
  62.                servletRequest.setAttribute("error","图书信息添加失败!");
  63.                return actionMapping.findForward("error");
  64.          }else if(a==2){
  65.              servletRequest.setAttribute("error","该图书信息已经添加!");
  66.              return actionMapping.findForward("error");
  67.          }else{
  68.              return actionMapping.findForward("bookAdd");
  69.         }
  70.        }
  71.        /***********************查询全部图书信息**************************/
  72.        private ActionForward bookQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  73.            String str=servletRequest.getParameter("f")+"like '%"+servletRequest.getParameter("key")+"%";
  74.        servletRequest.setAttribute("book",bookDAO.query(str));
  75.        System.out.print("条件查询图书信息时的str:"+str);
  76.        return actionMapping.findForward("bookQuery");
  77.        }
  78.        /***********************条件查询图书信息**************************/
  79.        private ActionForward bookifQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  80.        String str=null;
  81.        servletRequest.setAttribute("ifbook",bookDAO.query(str));
  82.        System.out.println("sssssssssssssssssssss");
  83.        return actionMapping.findForward("bookifQuery");
  84.        }
  85.         /***********************查询修改图书信息**************************/
  86.         private ActionForward bookModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  87.             BookForm bookForm=(BookForm)actionForm;
  88.             System.out.println("查询修改图书信息:"+servletRequest.getParameter("ID"));
  89.             bookForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  90.             servletRequest.setAttribute("bookQueryif",bookDAO.queryM(bookForm));
  91.             return actionMapping.findForward("bookQueryModify");
  92.         }
  93.         /***********************查询图书详细信息**************************/
  94.         private ActionForward bookDetail(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  95.             BookForm bookForm=(BookForm)actionForm;
  96.             bookForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  97.             servletRequest.setAttribute("bookDetail",bookDAO.queryM(bookForm));
  98.             return actionMapping.findForward("bookDeatil");
  99.         }
  100.         /***********************修改图书信息**************************/
  101.         private ActionForward bookModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  102.             BookForm bookForm=(BookForm)actionForm;
  103.             bookForm.setBarcode(bookForm.getBarcode());
  104.             bookForm.setBookName(bookForm.getBookName());
  105.             bookForm.setTypeId(bookForm.getTypeId());
  106.             bookForm.setAuthor(bookForm.getAuthor());
  107.             bookForm.setTranslator(bookForm.getTranslator());
  108.             bookForm.setIsbn(bookForm.getIsbn());
  109.             bookForm.setPrice(bookForm.getPrice());
  110.             bookForm.setPage(bookForm.getPage());
  111.             bookForm.setBookcaseid(bookForm.getBookcaseid());
  112.             bookForm.setStorage(bookForm.getStorage());
  113.             bookForm.setInTime(bookForm.getInTime());
  114.             bookForm.setOperator(bookForm.getOperator());
  115.             int ret=bookDAO.update(bookForm);
  116.             if(ret==0){
  117.                 servletRequest.setAttribute("error","修改图书信息失败!");
  118.                 return actionMapping.findForward("error");
  119.             }else{
  120.                 return actionMapping.findForward("bookModify");
  121.             }
  122.         }
  123.         /***********************删除图书信息**************************/
  124.         private ActionForward bookDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
  125.             BookForm bookForm=(BookForm)actionForm;
  126.             bookForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
  127.             int ret=bookDAO.delete(bookForm);
  128.             if(ret==0){
  129.                 servletRequest.setAttribute("error","删除图书信息失败!");
  130.                 return actionMapping.findForward("error");
  131.             }else{
  132.                 return actionMapping.findForward("bookDel");
  133.             }
  134.         }
  135. }