欢迎来到天天文库
浏览记录
ID:13926533
大小:49.50 KB
页数:19页
时间:2018-07-25
《重写struts1.x底层》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、重写Struts1.x底层重写Struts1.x底层.分类:Struts2010-03-2313:3152人阅读评论(0)收藏举报1.新建FormBean//生成get和set方法2.新建ActionMapping//<
2、forwardname="errpr"path="/Error.jsp">privateStringpath;privateStringname;privateStringtype;privateMapforward=newHashMap();生get和set方法3.新建ActionForwardprivateStringname;privateStringpath;生get和s
3、et方法4.在2步骤中的ActionMapping中新建Map5.新建ServletActionServlet重写init,在其中//读取Struts-config.xml,离不开dom4j的内容,当然struts不是用dom4j的Stringpath=this.getServletConfig().getInitParameter(“config”);this.getServletContext().getRealPath(path);Documentdocument=this.getDocument
4、(path);Stringxpath=“/struts-config/form-beans”6.新建Actionpackagecom.itcast.struts.sys;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;publicclassAction{publicActionForwardexecute(ActionMappingmapping,ActionFormform
5、,HttpServletRequestrequest,HttpServletResponseresponse){returnnull;}}7.新建ActionFormpackagecom.itcast.struts.sys;publicabstractclassActionForm{}8.新建LoginActionpackagecom.itcast.struts.action;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.
6、http.HttpServletResponse;importcom.itcast.struts.form.LoginForm;importcom.itcast.struts.sys.Action;importcom.itcast.struts.sys.ActionForm;importcom.itcast.struts.sys.ActionForward;importcom.itcast.struts.sys.ActionMapping;publicclassLoginActionextendsAct
7、ion{@OverridepublicActionForwardexecute(ActionMappingmapping,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse){System.out.println("form"+form);LoginFormloginForm=(LoginForm)form;System.out.println(loginForm.getUsername());if("sa".equa
8、ls(loginForm.getUsername())){returnmapping.findForward("success");}returnmapping.findForward("error");}}9.新建LoginFormpackagecom.itcast.struts.form;importcom.itcast.struts.sys.ActionForm;publicclassLoginFormextendsActionFor
此文档下载收益归作者所有