Struts2-ResultType-4-带参数的结果集

本文探讨了在Struts2框架中使用forward与redirect类型的result进行页面跳转的区别。forward类型保持同一个请求周期,可以直接从值栈获取数据;而redirect类型会发起新的请求,需通过URL参数传递数据。

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

场景:在请求的URL中传参,之后参数显示在jsp中

如果result的type是forward类型(type=dispatcher/chain),则共享值栈(因为相当于只有一次request请求),不需要在xml中取参数值
xml中

<action name="r1" >
            <result>/resultParam.jsp</result>
        </action>

        <action name="r2" class="com.resultParam.ResultParamAction">
            <result type="chain">r1</result>
        </action>

jsp中

from value stack<s:property value="type"></s:property>

如果result的type是redirect类型(type=”redirect”,redirectAction),则不共享值栈,需要在xml中取值后,在JSP中用OGNL表达式取值(ValueStack,StackContext)
xml中

<action name="r3" class="com.resultParam.ResultParamAction">
            <result type="redirect">/resultParam.jsp?type=${type}</result>
        </action>

        <action name="r4" class="com.resultParam.ResultParamAction">
            <result type="redirectAction">r1?type=${type}</result>
        </action>

jsp中

from stack context<s:property value="#parameters.type"></s:property>

访问图:这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值