struts2高级主题

高级动作的应用

       调用替代方法

               Struts2提供了对统配符的支持,可以再动作类中定义多个方法,在请求时选择正确的方法。
<action name="" class="">//默认execute方法
</action>
<action name="" class="" method="other">//调用other方法
</action>

动态方法调用

1.通配符方法的选择

<action name="aaa_*" method="{1}" class="">//多个*号就用,{1},{2},{3}等等接收映射,而且动作类中返回的是跟方法名一样的字符串。
<result name=""></result>
</action>

2.动态工作流

class{//可以在动作类中指定下一个页面,这样子可以动态的选择返回的页面。
private  String nextPage;
public String getNextPage(){
    return this.nextPage;
}

public  String add(){
if(xxx){
nextPage=...;
}else{
nextPage=...;
return "add";
}
}
}

<action name="aa_*" method="{1}" class="">
<result name="add">${nextPage}</result>
</action>

防止表单重复提交

1.使用<s:token/>表单标签

<s:form>
<s:token/>
</s:form>

<action>
<interceptor-ref name="tokenStack"/>//tokenStack包含了token拦截器,重复请求时会返回invalid.token。
<result name="success"></result>
<result name="invalid.token"></result>
</action>
<interceptor-stack  name="">//自定义拦截器
<interceptor-ref name="token">
<interceptor-ref  name="defaultStack">
</intercep-stack>
<interceptor-stack  name="">//tokenSession扩展了token拦截器,检查到重复请求时不会返回invalid.token,而是阻塞请求,返回最初请求的结果。实际效果就像没有重复提交一样
<interceptor-ref name="tokenSession">
<interceptor-ref  name="defaultStack">
</intercep-stack>
<interceptor-ref name="tokenSession">//可以指定拦截器拦截什么方法,不拦截什么方法。出现相同的方法,include优先于exclude
<param name="includeMethods">save,delete</param>
<param name="excludeMethods">save,delete</param>
</interceptor-ref>

自动显示等待页面

 
<action>
<interceptor-ref name="waitStack"/>//execAndWait这个拦截器要在最后声明,在这个拦截器后面的拦截器不会被执行
<result name="success"></result>
<result name="wait"></result>//除非动作结束返回页面,不然就都是等待页面,所以等待页面要定时刷新,看动作是不是返回结果了
</action>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值