<a href="actions/user1?type=1">传参数forward情况</a><br><br> <a href="actions/user2?type=1">传参数redirect情况</a>
Action:
private String type; public String getType() { return type; } public void setType(String type) { this.type = type; } public String execute() { this.type="2"; return "success"; }
struts.xml
<action name="user1" class="com.guojie.s2.actions.UserAction"> <result type="dispatcher">/dispatcher_success.jsp?t=${type}</result> </action> <action name="user2" class="com.guojie.s2.actions.UserAction"> <!-- ${}:从值栈中取值 --> <result type="redirect">/redirect_success.jsp?t=${type}</result> </action>
页面:
dispatcher
<h3> forward情况 </h3> 值栈取t:<s:property value="t" /><br><!-- 这一种取不到 --> 值栈取type:<s:property value="type"/><br><!-- 取得到 --> 上下文t:<s:property value="#parameters.t" /><br><!-- 取得到 --> 上下文取type:<s:property value="#parameters.type"/></br><!-- 取得到 --> attr取type值:<s:property value="#attr.type"/></br><!-- 取得到 --> attr取t值:<s:property value="#attr.t"/><!-- 这一种取不到 --> <br>
页面:redirect
值栈取t:<s:property value="t" /><br> 值栈取type:<s:property value="type"/><br> 上下文取t:<s:property value="#parameters.t" /><br><!-- 只有这种去得到 --> 上下文取type:<s:property value="#parameters.type"/><br><!-- 此时上下文取type取不到了,因为两次请求了 --> attr取type值:<s:property value="#attr.type"/><br> attr取t值:<s:property value="#attr.t"/>
forward情况
值栈取t:
值栈取type:2
上下文t:2
上下文取type:1
attr取type值:2
attr取t值:
redirect情况
值栈取t:
值栈取type:
上下文取t:2
上下文取type:
attr取type值:
attr取t值:
struts.xml 传递多个参数:
<result name="update" type="redirect">/backend/letter!init.jhtml?id=${id}&state=${state}</result>