BookCase.java~3~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:4k
- package com.action;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionForm;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForward;
- import com.actionForm.BookCaseForm;
- import org.apache.struts.action.Action;
- import com.dao.BookCaseDAO;
- public class BookCase extends Action {
- private BookCaseDAO bookCaseDAO=null;
- public BookCase(){
- this.bookCaseDAO=new BookCaseDAO();
- }
- public ActionForward perform(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- String action =request.getParameter("action");
- System.out.println("nbookCase*********************action="+action);
- if(action==null||"".equals(action)){
- return mapping.findForward("error");
- }else if("bookCaseAdd".equals(action)){
- return bookCaseAdd(mapping,form,request,response);
- }else if("bookCaseQuery".equals(action)){
- return bookCaseQuery(mapping,form,request,response);
- }else if("bookCaseModifyQuery".equals(action)){
- return bookCaseModifyQuery(mapping,form,request,response);
- }else if("bookCaseModify".equals(action)){
- return bookCaseModify(mapping,form,request,response);
- }else if("bookCaseDel".equals(action)){
- return bookCaseDel(mapping,form,request,response);
- }
- return mapping.findForward("error");
- }
- /***********************添加书架信息**************************/
- private ActionForward bookCaseAdd(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse){
- BookCaseForm bookCaseForm = (BookCaseForm) actionForm;
- System.out.println("servlet:"+servletRequest.getParameter("name"));
- bookCaseForm.setName(bookCaseForm.getName());
- int a=bookCaseDAO.insert(bookCaseForm);
- if(a==0){
- servletRequest.setAttribute("error","书架信息添加失败!");
- return actionMapping.findForward("error");
- }else if(a==2){
- servletRequest.setAttribute("error","该书架信息已经添加!");
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("bookcaseAdd");
- }
- }
- /***********************查询全部书架信息**************************/
- private ActionForward bookCaseQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- String str=null;
- servletRequest.setAttribute("bookcase",bookCaseDAO.query(str));
- return actionMapping.findForward("bookcaseQuery");
- }
- /***********************查询修改书架信息**************************/
- private ActionForward bookCaseModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- BookCaseForm bookCaseForm=(BookCaseForm)actionForm;
- bookCaseForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- servletRequest.setAttribute("bookCaseQueryif",bookCaseDAO.queryM(bookCaseForm));
- return actionMapping.findForward("bookCaseQueryModify");
- }
- /***********************修改书架信息**************************/
- private ActionForward bookCaseModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- BookCaseForm bookCaseForm=(BookCaseForm)actionForm;
- bookCaseForm.setName(servletRequest.getParameter("name"));
- int ret=bookCaseDAO.update(bookCaseForm);
- if(ret==0){
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("bookCaseModify");
- }
- }
- /***********************删除书架信息**************************/
- private ActionForward bookCaseDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- BookCaseForm bookCaseForm=(BookCaseForm)actionForm;
- bookCaseForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- int ret=bookCaseDAO.delete(bookCaseForm);
- if(ret==0){
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("bookCaseDel");
- }
- }
- }