欢迎来到天天文库
浏览记录
ID:51569736
大小:32.91 KB
页数:3页
时间:2020-03-13
《Struts2工程搭建的步骤.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、搭建Struts工程的步骤1.从stuts2官网下载FULL包然后解压2.从解压包里apps目录下有个struts-blank.war放到Tomcat下的webapps目录下3.启动tomcat,从webapps/stuts2-blank/web-inf/lib拷贝需要的JAR包到工程的WEB-INF/LIB下4.拷贝WEB.XML替换工程下的WEB.XML。主要是因为配置了struts的过滤器(控制器)struts22、>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterstruts2/*5.拷贝Tomcat/webapps/stuts2-blank/web-inf/classes/struts.xml到工程下src的根目录
2、>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
3、好了!开发Strust2程序的步骤:1.JSP页面开发.(form表单的内容可以绑定action的变量)2.Action的开发:自定义Action继承ActionSupport类,在Action里面写方法publicStringmethodName(){//必须public,返回值不行String,参数必须没有}3.配置Action.在Struts.xml中配置。Name对应页面Form的属性action的值,class,method4、tion.UserAction"method="registerUser">Register.jspRequltl类型类型名跳转方式Redirect用于跳转到JSP页面,使用的是sendRedirectDispatcher用于跳转到JSP页面,使用的是forwardredirectAction用户跳转到Action使用的是sendRedirectchain用户跳转到Action使用的是forward访问ServletApI对象方法:类名方法返回对象ActionC5、ontextget(“request”)getSession()getApplication()Map类型的返回值IOC方式RequestAware,SessionAware,Application类名方法返回对象ServletActionContextgetRequest()getResponse()getServletContext()HttpServletRequestHttpServletResponseServletContextIOC方式ServletRequestAware,ServletConte6、xtAwareStruts2面试:MVC:model—view—ControllerModel1/Model2Struts2的工作原理:IOC的概念用于访问Servletaapi对象ActionContext实现ACTION方式:继承ActionSupport或者实现Action接口Struts表单验证:在action类里面写一个方法publicvoidvalidateXxxx();添加错误信息this.addActionMessage();页面上使用struts的标签配置文件验7、证:
4、tion.UserAction"method="registerUser">Register.jspRequltl类型类型名跳转方式Redirect用于跳转到JSP页面,使用的是sendRedirectDispatcher用于跳转到JSP页面,使用的是forwardredirectAction用户跳转到Action使用的是sendRedirectchain用户跳转到Action使用的是forward访问ServletApI对象方法:类名方法返回对象ActionC
5、ontextget(“request”)getSession()getApplication()Map类型的返回值IOC方式RequestAware,SessionAware,Application类名方法返回对象ServletActionContextgetRequest()getResponse()getServletContext()HttpServletRequestHttpServletResponseServletContextIOC方式ServletRequestAware,ServletConte
6、xtAwareStruts2面试:MVC:model—view—ControllerModel1/Model2Struts2的工作原理:IOC的概念用于访问Servletaapi对象ActionContext实现ACTION方式:继承ActionSupport或者实现Action接口Struts表单验证:在action类里面写一个方法publicvoidvalidateXxxx();添加错误信息this.addActionMessage();页面上使用struts的标签配置文件验
7、证:
此文档下载收益归作者所有