BookType.java~8~
上传用户: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.BookTypeForm;
- import org.apache.struts.action.Action;
- import com.dao.BookTypeDAO;
- public class BookType extends Action {
- private BookTypeDAO bookTypeDAO = null;
- public BookType() {
- this.bookTypeDAO = new BookTypeDAO();
- }
- public ActionForward perform(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- String action =request.getParameter("action");
- System.out.println("nbookType*********************action="+action);
- if(action==null||"".equals(action)){
- request.setAttribute("error","您的操作有误!");
- return mapping.findForward("error");
- }else if("bookTypeAdd".equals(action)){
- return bookTypeAdd(mapping,form,request,response);
- }else if("bookTypeQuery".equals(action)){
- return bookTypeQuery(mapping,form,request,response);
- }else if("bookTypeModifyQuery".equals(action)){
- return bookTypeModifyQuery(mapping,form,request,response);
- }else if("bookTypeModify".equals(action)){
- return bookTypeModify(mapping,form,request,response);
- }else if("bookTypeDel".equals(action)){
- return bookTypeDel(mapping,form,request,response);
- }
- request.setAttribute("error","操作失败!");
- return mapping.findForward("error");
- }
- /***********************添加图书类型信息**************************/
- private ActionForward bookTypeAdd(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response){
- BookTypeForm bookTypeForm = (BookTypeForm) form;
- System.out.println("servlet:"+bookTypeForm.getTypeName());
- bookTypeForm.setTypeName(bookTypeForm.getTypeName());
- int a=bookTypeDAO.insert(bookTypeForm);
- if(a==0){
- request.setAttribute("error","图书类型信息添加失败!");
- return mapping.findForward("error");
- }else if(a==2){
- request.setAttribute("error","该图书类型信息已经添加!");
- return mapping.findForward("error");
- }else{
- return mapping.findForward("bookTypeAdd");
- }
- }
- /***********************查询全部图书类型信息**************************/
- private ActionForward bookTypeQuery(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response){
- String str=null;
- request.setAttribute("bookType",bookTypeDAO.query(str));
- return mapping.findForward("bookTypeQuery");
- }
- /***********************查询修改图书类型信息**************************/
- private ActionForward bookTypeModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- BookTypeForm bookTypeForm=(BookTypeForm)actionForm;
- bookTypeForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- servletRequest.setAttribute("bookTypeQueryif",bookTypeDAO.queryM(bookTypeForm));
- return actionMapping.findForward("bookTypeQueryModify");
- }
- /***********************修改图书类型信息**************************/
- private ActionForward bookTypeModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- BookTypeForm bookTypeForm=(BookTypeForm)actionForm;
- bookTypeForm.setTypeName(bookTypeForm.getTypeName());
- bookTypeForm.setDays(bookTypeForm.getDays());
- int ret=bookTypeDAO.update(bookTypeForm);
- if(ret==0){
- servletRequest.setAttribute("error","修改图书类型信息失败!");
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("bookTypeModify");
- }
- }
- /***********************删除图书类型信息**************************/
- private ActionForward bookTypeDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- BookTypeForm bookTypeForm=(BookTypeForm)actionForm;
- bookTypeForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- int ret=bookTypeDAO.delete(bookTypeForm);
- if(ret==0){
- servletRequest.setAttribute("error","删除图书类型信息失败!");
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("bookTypeDel");
- }
- }
- }