<说明:翻译自Struts2.1.6的文档,由于英语水平有限,很多地方翻译的不是很通顺,如果要看原文档,请参考Convention Plugin>
1 介绍
2 安装
3 Hello world
4 Code behind hello world
5 Results and result codes
6 Chaining
7 XWork packages
8 注解参考
8.1 Action annotation
8.2 InterceptorRef annotation
8.3 Result annotation
8.4 Namespace annotation
8.5 ResultPath annotation
8.6 ParentPackage annotation
8.7 ExceptionMapping Annotation
9 自动配置装载
10 故障排除
10.1 Tips
10.2 Common Errors
11 配置参考
1.介绍
从struts2.1开始捆绑规约(Convention)插件,该插件替代了原先的 CodeBehind 插件和Zero Config插件。该插件提供如下特性:
The Convention Plugin should require no configuration to use. Many of the conventions can be controlled using configuration properties and many of the classes can be extended or overridden.
2.安装
为了用这个插件,首先你必须把该插件的jar文件添加到你应用的WEB-INF/lib目录下(如果你把你的action打包成一个jar文件,请务必确认将struts.convention.action.disableJarScanning设置成ture)
3.Hello World
现在规约插件已经添加到你的应用了,让我们从一个简单的例子开始。该例子将用一个没有action的视图,该视图有URL定义。默认情况下,规约插件假设所有的视图都存放在WEB-INF/content。可以改变这个默认配置,通过修改Struts属性文件中的struts.convention.result.path来指定新的位置。Don't worry about trailing slashes, the Convention plugin handles this for you. Here is our hello world JSP:
<html> <body> Hello world! </body> </html>
If you start Tomcat (or whichever J2EE container you are using) and type in http://localhost:8080/hello-world into your browser you should get this result:
Hello world!
This illustrates that the Convention plugin will find results even when no action exists and it is all based on the URL passed to Struts.