使用struts2中的codebehind插件

使用struts2中的codebehind插件:

codebehind plugin是一个可以简化struts2配置的插件,虽然不能实现完全意义上的codebehind,至少已经做的不错了,期待新版本:-D

使用步骤:

1.确保你的应用已经可以使用struts2

2.添加struts2-codebehind-plugin-2.0.11.2.jar包到应用中

3.struts.xml中添加配置:<constant name="struts.codebehind.pathPrefix" value="/jsp/" /> 这里的value值填写jsp页面的根路径

然后就可以使用了,在不使用codebehind插件的时候,一般是这么写的:

写道
<action name="userlist" class="userListAction">
<result>/jsp/userlist.jsp</result>
</action>
 

使用codebehind插件的话,可以这么写:

扫描二维码关注公众号,回复: 697060 查看本文章
写道
<action name="userlist" class="userAction" />
 

result可以省略了,当然这里有一个约定,返回页面的路径为struts.codebehind.pathPrefix + package namespace + action name + action returntype + .jsp

我这里的环境:

struts.codebehind.pathPrefix  = /jsp/

package namespace = /

action name = userlist

action returntype = 为success时,值为空,为其他时,值为"-" + return type

所以返回的页面地址就为 /jsp/userlist.jsp

如果return type为input,地址就为 /jsp/userlist-input.jsp

配合表达式的使用,可以基本实现零配置:

写道
<action name="*" class="{1}Action" />
 

这样写不仅可以简化配置,而且可以达到规范文件布局的目的。如果有特殊的需要,也完全可以与手写配置文件相结合,用起来已经很方便了。

原文:http://www.cnblogs.com/modou/articles/1301597.html

猜你喜欢

转载自xiaoxuejie.iteye.com/blog/1562394
今日推荐