使用struts2中的codebehind插件
2015-08-13 11:37
405 查看
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插件的时候,一般是这么写的:
使用codebehind插件的话,可以这么写:
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
配合表达式的使用,可以基本实现零配置:
这样写不仅可以简化配置,而且可以达到规范文件布局的目的。如果有特殊的需要,也完全可以与手写配置文件相结合,用起来已经很方便了。
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" />
这样写不仅可以简化配置,而且可以达到规范文件布局的目的。如果有特殊的需要,也完全可以与手写配置文件相结合,用起来已经很方便了。
相关文章推荐
- java线程的同步互斥和通讯
- 对象的序列化与反序列化---IO学习笔记(四)
- java基础知识(一)
- Struts2 - 常用的constant总结
- java udp socket通信(仅发送)
- Eclipse种使用Maven
- 利用反射来改变String对象
- SpringMVC表单标签(7)
- eclipse 异常退出 再进入 选择命名空间路径后自动闪退(自动闪退)
- java并发编程--ThreadLocal的用法和分析
- Spring3.1新特性
- SpringMVC基于代码的配置方式(零配置,无web.xml)
- 如何修改eclipse的默认字符集和修改中文乱码
- Java int和integer的区别
- java程序由mysql转到sqlserver时在浮点数处理上遇到的错误
- Java DecimalFormat 用法
- 在spring官网下载jar包、源码、文档
- SpringMVC表单标签(6)
- 轻量级java ee 中的相关技术概述
- 一个有趣的程序,java的引用传参。