<param name="aliases"></param>拦截器的参数
2011-11-10 10:53
399 查看
这个拦截器在xwork的jar包里,它的作用是给参数起一个别名,可用于在action链中以不同的名字共享同一个参数,也可用于把http请求参数以不同的名字映射到action里。
拦截器有一个参数:aliasesKey,可通过在struts.xml中定义该拦截器时指定其值,默认值是aliases,表示一个别名的map。
下面以实现在action链中以不同的名字共享同一个参数为例:
struts.xml
<package name="test" namespace="/test">
<action name="aliasTestFrom" class="test.AliasInterceptorTestFromAction">
<result type="chain">aliasTestTo</result>
</action>
<action name="aliasTestTo" class="test.AliasInterceptorTestToAction">
<param name="aliases">#{'someList' : 'otherList'}</param>
<result>/test/alias_result.jsp</result>
</action>
</package>
param标签的name属性值应该和拦截器参数aliasesKey的值一样,这样拦截器才知道你是否指定了action的别名map。这个map应该象#{原参数名1 : 别名1, 原参数名2 : 别名2}这样的形式,这是一个定义map的OGNL表达式。
该拦截器已经包含在defaultStack中,因此上面没有显示的指定。
相应的,在本例中,test.AliasInterceptorTestFromAction里有一个字段someList:
AliasInterceptorTestFromAction.java
private List someList;
public List getSomeList() {
return someList;
}
public void setSomeList(List someList) {
this.someList = someList;
}
test.AliasInterceptorTestToAction里有一个字段otherList:
AliasInterceptorTestToAction.java
private List otherList;
public List getOtherList() {
return otherList;
}
public void setOtherList(List otherList) {
this.otherList = otherList;
}
注意:在AliasInterceptorTestToAction中不能有一个叫someList的字段,如果有的话,otherList最终的值将是AliasInterceptorTestToAction中的someList,而非AliasInterceptorTestFromAction的值。因为该拦截器的实现是在action的值栈里找到原参数名后设置给别名,如果两个action都有someList,而AliasInterceptorTestToAction位于栈顶,它的someList将被赋给otherList,这并不是我们所期望的结果。
很重要:注意::!!!!!someList也可以来自于http请求参数,因为拦截器如果在action的值栈里没有找到someList,还会在http请求参数里找。
拦截器有一个参数:aliasesKey,可通过在struts.xml中定义该拦截器时指定其值,默认值是aliases,表示一个别名的map。
下面以实现在action链中以不同的名字共享同一个参数为例:
struts.xml
<package name="test" namespace="/test">
<action name="aliasTestFrom" class="test.AliasInterceptorTestFromAction">
<result type="chain">aliasTestTo</result>
</action>
<action name="aliasTestTo" class="test.AliasInterceptorTestToAction">
<param name="aliases">#{'someList' : 'otherList'}</param>
<result>/test/alias_result.jsp</result>
</action>
</package>
param标签的name属性值应该和拦截器参数aliasesKey的值一样,这样拦截器才知道你是否指定了action的别名map。这个map应该象#{原参数名1 : 别名1, 原参数名2 : 别名2}这样的形式,这是一个定义map的OGNL表达式。
该拦截器已经包含在defaultStack中,因此上面没有显示的指定。
相应的,在本例中,test.AliasInterceptorTestFromAction里有一个字段someList:
AliasInterceptorTestFromAction.java
private List someList;
public List getSomeList() {
return someList;
}
public void setSomeList(List someList) {
this.someList = someList;
}
test.AliasInterceptorTestToAction里有一个字段otherList:
AliasInterceptorTestToAction.java
private List otherList;
public List getOtherList() {
return otherList;
}
public void setOtherList(List otherList) {
this.otherList = otherList;
}
注意:在AliasInterceptorTestToAction中不能有一个叫someList的字段,如果有的话,otherList最终的值将是AliasInterceptorTestToAction中的someList,而非AliasInterceptorTestFromAction的值。因为该拦截器的实现是在action的值栈里找到原参数名后设置给别名,如果两个action都有someList,而AliasInterceptorTestToAction位于栈顶,它的someList将被赋给otherList,这并不是我们所期望的结果。
很重要:注意::!!!!!someList也可以来自于http请求参数,因为拦截器如果在action的值栈里没有找到someList,还会在http请求参数里找。
相关文章推荐
- strut2下载文件的“ <param name="inputName"> tag specified for this action.”异常
- <param name="allowScriptAccess" value="never"/>是什么意思
- struts2文件下载及 <param name="inputName">inputStream</param>的理解
- flex <param name="wmode" value="transparent">鼠标滚轮控制问题
- struts2文件下载及 <param name="inputName">inputStream</param>的理解
- hibernate中配置<param name="sequence">SEQ_CLASS_ID</param>
- <a href="<s:url action="navDel" ><s:param name="id" value="pid"/></s:url>"> 删除 </a>
- struts2文件下载及 <param name="inputName">inputStream</param>的理解
- 使用action属性接收参数<a href="user/user!add?name=a&age=8">添加用户</a>
- /// <summary> /// 搜索 /// </summary> /// <param name="k"></param> /// <param name="cid"></param> ///
- flex <param name="wmode" value="transparent">鼠标滚轮控制问题
- struts2文件下载及 <param name="inputName">inputStream</param>的理解
- 接口参数如果后台返回"<null>",IOS 前台会崩溃,返回“”OK
- struts.xml中为什么加上<constant name="struts.devMode" value="true" />就出错
- 在eclipse中运行工程时 出现<ConnectionProperties> <PropertyCategory name="Connection/Authentication">的解决方法
- <s:token name="contact1"/> 拦截器 防止重复提交
- XST - "WARNING: Xst:766 - file_name (Line #). Generating a Black Box for component <component_name>"
- 回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/>
- System.ArgumentException: 回发或回调参数无效。在配置中使用 < pages enableEventValidation="true"/> 或在页面中使用 <% @ Page
- jsp中<a href=""></a>标签传递参数乱码问题解决