`
summer_021
  • 浏览: 55427 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

struts.xml向页面传参

阅读更多
请求地址:
  	<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}&amp;state=${state}</result>
分享到:
评论
1 楼 wnjustdoit 2012-07-25  
给力。。。。

相关推荐

Global site tag (gtag.js) - Google Analytics