struts2 convention-plugin实现零配置
零配置并不是没有配置,而是通过约定大于配置的方式,大量通过约定来调度页面的跳转而使得配置大大减少。使得Action等配置不必写在Struts.xml中。
convention-plugin的约定
1. 默认所有的结果页面都存储在WEB-INF/content下,你可以通过设置struts.convention.result.path这个属性的值来改变到其他路径。
<constant name="struts.convention.result.path" value="/WEB-INF/page" />
2. 默认包路径包含action,actions,struts,struts2的所有包都会被struts作为含有Action类的路径来搜索。
你可以通过设置struts.convention.package.locators属性来修改这个配置。
<constant name="struts.convention.package.locators" value="web,action" />
<!--包路径包含web和action的将被视为Action存在的路径来进行搜索。-->
3.Convention 从找到的package以及其子package中寻找 com.opensymphony.xwork2.Action 的实现以及以Action结尾的类
com.example.actions.MainAction
com.example.actions.products.Display (implements com.opensymphony.xwork2.Action)
4.Convention通过如下规则确定URL的具体资源部分:去掉类名的Action部分。然后将将每个分部的首字母转为小写,用’-’分割
可以自定义分隔符:
<constant name="struts.convention.action.name.separator" value="-" />
举例:
- UserAction->user
- UserDetailAction ->user-detail
- com.ustb.web.user.detail.UserDetailAction ->/WEB-INF/content/user/detail/user-detail.jsp
通过注解来配置
一个方法被@Action注释后,只是多了一种调用方式,而不是说覆盖了原来的调用方式
public class HelloAction extends ActionSupport {
@Action("action1")
//调用路径:/action1!method1.action
//映射路径: /WEB-INF/content/action1.jsp
public String method1() {
return SUCCESS;
}
//调用路径:/user/action2!method2.action
//映射路径: /WEB-INF/content/user/action2.jsp
@Action("/user/action2")
public String method2() {
return SUCCESS;
}
}
@Actions注释
public class HelloAction extends ActionSupport {
//可以通过两种路径调用注释方法,会映射到对应的文件
@Actions({
@Action("/different/url"), //调用:/different/url!method1.action 映射:/WEB-INF/content/different/url-error.jsp
@Action("/another/url") //调用:/another/url!method1.action 映射:/WEB-INF/content/another/url-error.jsp
})
public String method1() {
return “error”;
}
@Namespace 注释
@Namespace("/other") //记得加斜杠
public class HelloWorld extends ActionSupport {
// 调用:/other/hello-world!method1.action
public String method1() {
return “error”;
}
@Action("url")
// 调用:/other/url!method2.action
public String method2() {
return “error”;
}
@Action("/different/url")
// 调用:/different/url!method3.action
public String method3() {
return “error”;
}
}
@Result注释
public class HelloWorld extends ActionSupport {
@Action(
value="test01",
results={
@Result(
name="error",
location="/pages/test01/say-hello.jsp",
params={
"param1","${param1}",
"param2","${param2}"
}
)
}
)
public String AgentLogin() throws Exception{
}
}
struts2 convention-plugin实现零配置的更多相关文章
- Struts2 Convention Plugin ( struts2 零配置 )
Struts2 Convention Plugin ( struts2 零配置 ) convention-plugin 可以用来实现 struts2 的零配置.零配置的意思并不是说没有配置,而是通过约 ...
- struts2采用convention-plugin实现零配置
最近开始关注struts2的新特性,从这个版本开始,Struts开始使用convention-plugin代替codebehind-plugin来实现struts的零配置. 配置文件精简了,的确是简便 ...
- Convention插件 struts零配置
http://blog.csdn.net/spyjava/article/details/13631961系列课程使用 注解:http://www.yiibai.com/struts_2/struts ...
- 菜鸟学Struts2——零配置(Convention )
又是周末,继续Struts2的学习,之前学习了,Struts的原理,Actions以及Results,今天对对Struts的Convention Plugin进行学习,如下图: Struts Conv ...
- 从struts2.1开始Convention零配置
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该 ...
- struts2 Convention插件零配置,使用注解开发
从struts21开始,struts2不再推荐使用codebehind作为零配置插件,而是改用Convention插件来支持零配置.与以前相比较,Convention插件更彻底. 使用Conventi ...
- Struts2 注解零配置方法(convention插件使用)
最近接触到一个新的项目,是做一个使用S2SH的电子商务商城的二次开发.之前使用过S2SH,在此之前的项目中,Struts2 使用的是XML配置而这个项目是使用注解.在这个项目中,注解还不需要使用Act ...
- spring+hibernate+struts2零配置整合
说句实话,很久都没使用SSH开发项目了,但是出于各种原因,再次记录一下整合方式,纯注解零配置. 一.前期准备工作 gradle配置文件: group 'com.bdqn.lyrk.ssh.study' ...
- 13、零配置Struts2开发
Convention 插件 从 Struts 2.1 开始, Struts 可以使用 Convention 插件来支持零配置: Convention 插件完全抛弃配置信息, 不仅不需要使用 strut ...
- struts2使用Convention Plugin在weblogic上以war包部署时,找不到Action的解决办法
环境: struts 2.3.16.3 + Convention Plugin 2.3.16.3 实现零配置 现象:以文件夹方式部署在weblogic(10.3.3)上时一切正常,换成war包部署,运 ...
随机推荐
- ASP.NET MVC轻教程 Step By Step 9——分页
现在我们要把Index视图的留言信息进行分页显示. Step 1. 创建路由 我们希望以类似地址http://localhost:41583/Page1来表示第一页,Page2表示第二页,以此类推.在 ...
- POJ Code the Tree 树的pufer编号
Code the Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2259 Accepted: 859 Desc ...
- King's Quest
poj1904:http://poj.org/problem?id=1904 题意:国王有n个儿子,现在这n个儿子要在n个女孩里选择自己喜欢的,有的儿子可能喜欢多个,最后国王的向导给出他一个匹配,匹配 ...
- servlet和struts2一起使用,实现绝对路径下的图片输出到jsp页面
如果我们在web.xml中配置的struts2的接收请求的路径为: <filter-mapping> <filter-name>struts2</filter-name& ...
- android中保存一个ArrayList到SharedPreferences的方法
保存: public static boolean saveArray() { SharedPrefernces sp=SharedPrefernces.getDefaultSharedPrefern ...
- 几种交换两个数函数(swap函数)的写法和解析
#include <iostream> using namespace std; /*值传递,局部变量a和b的值确实在调用swap0时变化了,当结束时,他们绳命周期结束*/ void sw ...
- 【CF】244C Checkposts
题目需要求啥很明确了.主要思想是先计算机联通块,然后每个块内找到一个最小值(以及该值的次数).最小值和结果1,次数乘积为结果2.联通块tarjan可解. /* 427C */ #include < ...
- 深入浅出Node.js (11) - 产品化
11.1 项目工程化 11.1.1 目录结构 11.1.2 构建工具 11.1.3 编码规范 11.1.4 代码审查 11.2 部署流程 11.2.1 部署环境 11.2.2 部署操作 11.3 性能 ...
- Win8/Win7系统下用IE11浏览器调试js脚本
作为一个web开发者,调试js脚本是工作中的一部分,但是并不是所有的浏览器都会很好的兼容js脚本的.随着win8系统的发布,ie11也慢慢进入了大家的视野,ie11的众多优点及新特性就不必多说了(全面 ...
- js 的 提交
<script type="text/javascript"> function sub(){ if(document.form1.xingming.value==&q ...