使用struts2中的codebehind插件

本文介绍Struts2中的CodeBehind插件使用方法,该插件能简化Struts2配置,通过约定返回页面路径,实现零配置。文章详细讲解了插件配置步骤及如何结合表达式使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用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插件的话,可以这么写:

写道
<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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值