`

result类型

阅读更多

Struts2 result类型

 

1.dispatcher:服务器跳转到页面,通常来处理JSP,默认类型。

 

2.redirect:重定向到页面。

 

Action:

public String redirect() {
		message = "message中有值";
		return "redirect";
}

 struts.xml:

<package name="chapter3" namespace="/chapter3" extends="struts-default">
		<action name="redirectAction" class="chapter3.action.Chapter3Action" method="redirect">
			<result name="redirect" type="redirect">/redirect.jsp</result>
		</action>
</package>

 注意的地方:外部中转不能带值过去,并且页面不能受保护

 

传参数:

<action name="redirectAction" class="chapter3.action.Chapter3Action" method="redirect">
	<result name="redirect" type="redirect">/redirect.jsp?message=${message}</result>
</action>

 页面:

${param.message}<br>


 

3.chain:服务端跳转到Action;

action

public String action2() {
	message = "我是action2中设置的值";
	return "action2";
}

 

struts.xml

<package name="chapter32" namespace="/chapter32" extends="struts-default">
	<action name="action2" class="chapter3.action.Chapter3Action" method="action2">
		<result name="action2" type="chain">
			<param name="actionName">redirectAction</param>
			<param name="namespace">/chapter3</param>
		</result>
	</action>
</package>

 

4.redirectAction:外部跳转到Action;

 

action:

public String action3() {
	message = "我是action3中设置的值";
	return "action3";
}

 

struts.xml

<action name="action3" class="chapter3.action.Chapter3Action" method="action3">
	<result name="action3" type="redirectAction">redirectAction</result>
</action>

 跨命名空间的外部跳转:

public String action4() {
	message = "我是action4中设置的值";
	return "action4";
}

 

<action name="action4" class="chapter3.action.Chapter3Action" method="action4">
	<result name="action4" type="redirectAction">
		<param name="actionName">redirectAction</param>
		<param name="namespace">/chapter3</param>
	</result>
</action>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics