BookCaseAdd.java~68~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:5k
- 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 BookCaseAdd extends Action {
- private BookCaseDAO bookCaseDAO=null;
- public BookCaseAdd(){
- this.bookCaseDAO=new BookCaseDAO();
- }
- public ActionForward perform(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- String action =servletRequest.getParameter("action");
- System.out.println("nbookCase*********************action="+action);
- if(action==null||"".equals(action)){
- return actionMapping.findForward("error");
- }else if("bookCaseAdd".equals(action)){
- return bookCaseAdd(actionMapping,actionForm,servletRequest,servletResponse);
- }else if("bookCaseQuery".equals(action)){
- return bookCaseQuery(actionMapping,actionForm,servletRequest,servletResponse);
- }else if("bookCaseModifyQuery".equals(action)){
- return bookCaseModifyQuery(actionMapping,actionForm,servletRequest,servletResponse);
- }else if("bookCaseModify".equals(action)){
- return bookCaseModify(actionMapping,actionForm,servletRequest,servletResponse);
- }else if("bookCaseDel".equals(action)){
- return bookCaseDel(actionMapping,actionForm,servletRequest,servletResponse);
- }
- return actionMapping.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");
- }
- }
- }