我们需要使用到的jar包:
- struts2-convention-plugin-2.1.8.jar
- struts2-core-2.1.8.jar
- xwork-core-2.1.6.jar
- commons-fileupload-1.2.1.jar
- freemarker2.3.16.jar
struts.xml中Convention配置
1.1. 设置结果页面路径
默认所有的结果页面都存储在WEB-INF/content下,你可以通过设置struts.convention.result.path这个属性的值来改变到其他路径。如:
- <constant name="struts.convention.result.path" value="="/WEB-INF/template/" />
这样你在就必须将你需要跳转的页面放在template下面
struts2支持.jsp .html .htm .vm格式的文件。
下面是actiong和结果模版的映射关系:
URL Result File that could match Result Type
/hello success /WEB-INF/content/hello.jsp Dispatcher
/hello success /WEB-INF/content/hello-success.htm Dispatcher
/hello success /WEB-INF/content/hello.ftl FreeMarker
/hello input /WEB-INF/content/hello-world-input.vm Velocity
/hello error /WEB-INF/content/test/test2/hello-error.html Dispatcher
以上的内容来自struts2的文档
[url]http://struts.apache.org/2.1.6/docs/convention-plugin.html [/url]
当然,简单的通过默认的方式来进行配置不能完全满足实际项目的需要。所幸,convention的零配置是非常灵活的。
1.2. 设置Convention搜索包
默认包路径包含action,actions,struts,struts2的所有包都会被struts作为含有Action类的路径来搜索。你可以通过设置struts.convention.package.locators属性来修改这个配置。如:
- <constant name="struts.convention.package.locators" value="web,action" />
则定义了在项目中,包路径包含web和action的将被视为Action存在的路径来进行搜索。
Com.ustb.web.*/com.ustb.action.*都将被视为含有Action的包路径而被搜索。
接着,Convention从前一步找到的package以及其子package中寻找 com.opensymphony.xwork2.Action 的实现以及以Action结尾的类:
com.example.actions.MainAction
com.example.actions.products.Display (implements com.opensymphony.xwork2.Action)
com.example.struts.company.details.ShowCompanyDetailsAction
1.3. 命名空间
命名空间。从定义的.package.locators标示开始到包结束的部分,就是命名空间。举个例子:
xxx.xxx.action.shop.helloAction的命名空间是:”/shop”。
xxx.xxx.action.shop.detail.UserAction的命名空间是:”/shop/detail”
1.4. Actin类名路径分割
Convention通过如下规则确定URL的具体资源部分:去掉类名的Action部分。然后将将每个分部的首字母转为小写,用’-’分割,你可以设置struts.convention.action.name.separator 如
- <contant name="struts.convention.action.name.separator" value="_" />
还是举个例子:
HelloAction->hello HelloWorldAction ->hello-world。
结合上面的。
对于action.shop.HelloAction,映射的url就是/WEB-INF/template/shop/hello_test.jsp
相关推荐
Struts2插件convention
struts2的convention插件使用.docx )
struts2-Convention插件详细使用
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
无需配置Convention即可使用Convention,Convention的某些约束习惯可以通过配置属性来控制,您也可以在类中覆写其中的方法来达到扩展目地。
struts2 convention plugin(插件)测试项目
从 Struts 2.1 开始,Struts 2 改为使用 Convention 插件来支持零配置。Convention 插件彻底地抛弃了配置信息,不仅不需要使用 struts.xml 文件进行配置,甚至不需要使用 Annotation 进行配置。而是由 Struts 2 根据...
如何使用插件convention来实现struts2框架的零配置以及整合ssh架构
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
将 Struts 2 项目下 struts2-convention-plugin-2.1.6.jar、struts2-rest-plugin-2.1.6.jar 两个 JAR 包复制到 Web 应用的 WEB-INF/lib 路径下。 由于 Struts 2 的 REST 插件还需要将提供 XML、JSON 格式的数据,...
Struts开始使用convention-plugin代替codebehind-plugin来实现struts的零配置,使用Convention插件,你需要此JAR文件
Struts2 的第三方插件 使用注解的方式配置struts.xml文件
SSH整合+struts convention插件小示例 全程使用注解扫包,无struts action的配置文件,无Hibernate配置文件, Spring自动扫包来获取bean 数据库内容太简单,不再上传。 只是一个小实例。 请用MyEclipse导入项目。 我...
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
1 Convention插件 1.1 设置结果页面路径 默认所有的结果页面都存储在WEB-INF/content下,你可以通过设置struts.convention.result.path这个属性的值来改变到其他路径。如: Xml代码 <constant name="struts....
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
安装使用Convention插件,你需要将其JAR文件放到你应用的WEB-INF/lib目录中,你也可以在你Macen项目的POM文件中添加下面包依赖 <groupId>org.apache.struts <artifactId>struts2-convention-plugin ...
改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级了《Struts 2权威指南》,第二版改写了第一版中所有程序...
2.如果您使用基于Jakarta插件,请升级到Apache Struts 2.3.32或2.5.10.1版本。(强烈推荐) 3.升级到2.3.32所用到的jar包: freemarker-2.3.22.jar ognl-3.0.19.jar struts2-convention-plugin-2.3.32.jar struts2-...