Struts2--Result类型
4种 result类型: dispatcher, redirect, chain, redirectAction
dispatcher, redirect只能跳转到jsp等页面
chain,redirectAction是专门跳转到action页面的
dispatcher,chain 是服务器端跳转
redirect,redirectAction是客户端跳转
总结;:
dispatcher: 默认, 服务器跳转, 只能接jsp等页面
redirect: 客户端跳转, 只能接jsp等页面
chain: 服务器端调转, 可以接action
redirectAction: 客户端跳转, 可以接action
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="resultTypes" namespace="/r" extends="struts-default"> <action name="r1"> <result type="dispatcher">/r1.jsp</result> </action> <action name="r2"> <result type="redirect">/r2.jsp</result> </action> <action name="r3"> <result type="chain">r1</result> </action> <action name="r4"> <result type="redirectAction">r2</result> </action> </package> </struts>
jsp:
<li><a href="r/r1">dispatcher</a></li> <li><a href="r/r2">redirect</a></li> <li><a href="r/r3">chain</a></li> <li><a href="r/r4">redirectAction</a></li>
dispacher: url: r/r1 显示r1
redirect: url: r2.jsp 显示r2
chain: url: r/r3 显示r1
redirectAction: r2.jsp 显示r2
如果r1在别的包如何处理?
<action name="r3"> <result type="chain">r1</result>
</action>
<action name="r3"> <result type="chain">
<param name="actionname">dash</param>
<param name="namespace">/pack</param>
</result> </action>