Struts2.1.6中的规约插件

<说明:翻译自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插件。该插件提供如下特性:

  • 通过包名称规约定位action
  • 通过名称规约定位视图(如JSP,FreeMarker等)
  • 通过URL名称规约定位类名
  • 通过名称规约定位包名
  • SEO compliant ULRs(例如 my-action 而不是MyAction)
  • 利用注解复写Action名
  • 利用注解复写拦截器
  • 利用注解复写名称空间
  • 利用注解复写XWork包
  • Default action and result handling (i.e. /products will try com.example.actions.Products as well as com.example.actions.products.Index)

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:

WEB-INF/content/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:

WEB-INF/content/hello-world.jsp
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.

你可能感兴趣的:(tomcat,Web,freemarker,jsp,struts)