struts2 resultType为chain时 传值

本文详细介绍了在Struts2框架中处理表单验证失败后的页面跳转问题,通过合理配置action和interceptor,实现表单验证失败后既跳转回当前页面又显示错误信息的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

应用场景:

  a页面保单提交进行validation验证,如果验证不通过则跳转到当前页面并展现已有数据列表,也就是a页面既包含新增表单,又有列表展现。

  一开始的想法是用redirect 类型,可以这个类型明显不行,拿不到验证不通过的信息。

 后来决定用chain,但是跳转是跳转过来,可没有去走chain跳转到action中的方法

如下列代码:aAction验证不通过,chain到bList,(备注 :1,两个在同一个namespace,2,bList result为input类型的一定要配置)

但是却没有走listB这个方法,而是直接把验证错误信息展现到b_list.jsp。显然结果不对。 

<action name="aAction" class="com.AAction" method="detailA">
            <result name="success" type="redirect">AList.html?id=${id}</result>
            <result name="input" type="chain">bList</result>
</action>

<action name="bList" class="com.BAction" method="listB">
            <result name="success" type="dispatcher">b_list.jsp</result>
            <result name="input" type="dispatcher">b_list.jsp</result>
</action>
 

解决方法:

<action name="bList" class="com.BAction" method="listB">
            <result name="success" type="dispatcher">b_list.jsp</result>
            <result name="input" type="dispatcher">b_list.jsp</result>
            <interceptor-ref name="default-stack">
                <param name="workflow.excludeMethods">bList</param>
            </interceptor-ref>
</action>

加上这段配置,就可以执行方法后并且一起把错误信息输出到页面。

 

补充文章:http://psjay.com/struts2-validate-chain-important-point.html

 

 

转载于:https://www.cnblogs.com/iusmile/archive/2012/07/07/2581014.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值