`
反求诸己
  • 浏览: 534948 次
  • 性别: Icon_minigender_1
  • 来自: 湖南娄底
社区版块
存档分类
最新评论

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

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

分享到:
评论

相关推荐

    STRUTS2:零配置插件CodeBehind

    STRUTS2:零配置插件CodeBehind

    Struts2权威指南完整版

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    struts2注解详解

    从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...

    Struts2注解使用说明文档

    从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...

    struts2零配置convention-plugin

    从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...

    struts2注解使用.doc

    从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...

    STRUTS2 Convention零配置

    从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...

    深入浅出Struts2(附源码)

    26.3 CodeBehind插件 319 26.4 小结 321 第27章 Ajax 322 27.1 Ajax概述 322 27.2 Dojo的事件系统 323 27.3 使用Struts Dojo插件 324 27.4 head标签 324 27.5 div标签 325 27.5.1 示例程序1 326 27.5.2 ...

    struts2 Annotation 版本学习心得与例子

    Struts2的“零配置”特性由struts2-codebehind-plugin-2.1.2.jar插件支持,使用时记得将其拷入WEB-INF/lib下; 如果用的是Annotation的Struts2,就要将struts.xml去掉,否则即使将struts.xml中的内容注销,也会报错;

    struts2注解详细说明

    转换基于Codebehind项目到Convention跳转到此页面,查看需要修改的变化和小提示如果你想在你系统中结合Convention插件使用REST。需要在你项目的struts.xml中添加如下配置    name="struts.convention.action....

    struts2urlplugin:Struts2 插件支持 URL 中的模式匹配,用于动作映射器

    Struts2 插件支持 URL 中的模式匹配以进行动作映射 Struts 2 的插件,允许开发人员控制 URL 如何映射到他们的操作: 使用正则表达式; 通过路径或命名空间将参数传递给动作; 控制允许的 HTTP 方法; 使用替代...

    Struts 2.1 权威指南 part13 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part04 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part01 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part02 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part06 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part03 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

Global site tag (gtag.js) - Google Analytics