ReaderType.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.ReaderTypeForm;
- import org.apache.struts.action.Action;
- import com.dao.ReaderTypeDAO;
- public class ReaderType extends Action {
- private ReaderTypeDAO readerTypeDAO=null;
- public ReaderType(){
- this.readerTypeDAO=new ReaderTypeDAO();
- }
- public ActionForward perform(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- String action =request.getParameter("action");
- System.out.println("nreaderType*********************action="+action);
- if(action==null||"".equals(action)){
- return mapping.findForward("error");
- }else if("readerTypeAdd".equals(action)){
- return readerTypeAdd(mapping,form,request,response);
- }else if("readerTypeQuery".equals(action)){
- return readerTypeQuery(mapping,form,request,response);
- }else if("readerTypeModifyQuery".equals(action)){
- return readerTypeModifyQuery(mapping,form,request,response);
- }else if("readerTypeModify".equals(action)){
- return readerTypeModify(mapping,form,request,response);
- }else if("readerTypeDel".equals(action)){
- return readerTypeDel(mapping,form,request,response);
- }
- return mapping.findForward("error");
- }
- /***********************添加读者类型信息**************************/
- private ActionForward readerTypeAdd(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse){
- ReaderTypeForm readerTypeForm = (ReaderTypeForm) actionForm;
- System.out.println("servlet:"+servletRequest.getParameter("name"));
- readerTypeForm.setName(readerTypeForm.getName());
- int a=readerTypeDAO.insert(readerTypeForm);
- 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("readerTypeAdd");
- }
- }
- /***********************查询全部读者类型信息**************************/
- private ActionForward readerTypeQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- String str=null;
- servletRequest.setAttribute("readerType",readerTypeDAO.query(str));
- return actionMapping.findForward("readerTypeQuery");
- }
- /***********************查询修改读者类型信息**************************/
- private ActionForward readerTypeModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- ReaderTypeForm readerTypeForm=(ReaderTypeForm)actionForm;
- readerTypeForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- servletRequest.setAttribute("readerTypeQueryif",readerTypeDAO.queryM(readerTypeForm));
- return actionMapping.findForward("readerTypeQueryModify");
- }
- /***********************修改读者类型信息**************************/
- private ActionForward readerTypeModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- ReaderTypeForm readerTypeForm=(ReaderTypeForm)actionForm;
- readerTypeForm.setName(readerTypeForm.getName());
- readerTypeForm.setNumber(readerTypeForm.getNumber());
- int ret=readerTypeDAO.update(readerTypeForm);
- if(ret==0){
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("readerTypeModify");
- }
- }
- /***********************删除读者类型信息**************************/
- private ActionForward readerTypeDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- ReaderTypeForm readerTypeForm=(ReaderTypeForm)actionForm;
- readerTypeForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- int ret=readerTypeDAO.delete(readerTypeForm);
- if(ret==0){
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("readerTypeDel");
- }
- }
- }