Struts2 Convention 系列 1
2016-03-17 16:18
429 查看
struts2中的convention插件,可以大大地减少开发过程中的配置量。更多更具体配置信息,请文档:点击打开链接以下以maven开发为例。
配置结果如下:
流程
1、工具包a) struts2-core.jar;struts2的核心包。b) struts2-convention-plugin;convention插件。c) struts2-config-browser-plugin;查看映射情况。2、web.xml配置,略。3、struts.xml配置a) 设置为开发模式。<constant name="struts.devMode" value="true" />b) 自动加载。(或许会出现NullPointerException异常)<constant name="struts.convention.classes.reload" value="true"></constant>c) 结果映射路径。<constant name="struts.convention.result.path" value="/WEB-INF" /> 具体配置如下:<struts><!-- 默认编码 --><constant name="struts.i18n.encoding" value="utf8" /><!-- 上传文件大小限制为10M --><constant name="struts.multipart.maxSize" value="20971520" /><!-- 是否显示详细错误信息 --><constant name="struts.devMode" value="true" /><!-- 是否在struts.xml修改后重新加载 ,默认false --><constant name="struts.configuration.xml.reload" value="true" /><!-- 是否每次HTTP请求到达时,系统都重新加载资源文件,默认false --><constant name="struts.i18n.reload" value="false" /><!-- 国际化资源文件名称 --><constant name="struts.custom.i18n.resources" value="i18n" /><!-- 自动加载 --><constant name="struts.convention.classes.reload" value="true"></constant><!-- 扫描的包 --><constant name="struts.convention.package.locators" value="struts2,action" /><!-- :去掉类名的Action部分。然后将将每个分部的首字母转为小写,用’-’分割 --><constant name="struts.convention.action.name.separator" value="-" /><constant name="struts.convention.result.path" value="/WEB-INF" /></struts>4、请求页面 a) /WEB-INF/index.jsp
<form action="user/test"><input type="submit" value="test"/></form>5、action a) src/com/action/user/TestAcion.javapackage com.action.user;import com.opensymphony.xwork2.Action;public class TestAction implements Action{<span> </span>@Override<span> </span>public String execute() throws Exception {<span> </span>System.out.println("convertion test result is true");<span> </span>return SUCCESS;<span> </span>}}6、结果页面 a) /WEB-INF/user/test.jsp;b) /WEB-INF/user/test-error.jsp;注:用的版本是2.3.24,虽然上面配置去掉“-”,但如果页面是“testerror.jsp”,会把中间的一个”e”冲掉,变成”testrror.jsp”。7、查看配置信息a) 地址栏输入:localhost:....../项目/config-browser/acionName.action;可以查看到映射等配置的结果。如果没有结果,那就是映射失败啰。
附图:
maven配置:<dependency><groupId>org.apache.struts</groupId><artifactId>struts2-core</artifactId><version>2.3.24</version></dependency><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-convention-plugin</artifactId><version>2.3.24</version></dependency><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-config-browser-plugin</artifactId><version>2.3.24</version></dependency>结构如下:相关文章推荐
- Struts - 标签库
- struts1.0于struts2.0的比较
- Struts2中关于namespace的学习心得
- Struts2----自定义action的学习心得
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!welcome] associ
- struts2
- struts 学习笔记
- struts2框架架构流程
- struts2.0拦截器(实现未登录的用户不能访问系统的页面)(转)
- Struts2 面试题分析
- Struts2+jQuery+JSON实现异步交互
- 软件开发疑惑解答
- ajax ssh 整合
- 关于struts2框架学习
- struts2 @Action给方法注解
- struts2登陆拦截器
- struts2框架原理
- web.xml
- web.xml
- struts2框架原理