forward和redirect的四大区别:
Forward:跳转后地址栏不发生变化;可以得到request中的数据;forward只能到内网路径;
Forward后面的语句会打印其后面的语句,所以要写return,{过程:执行完forward语句跳转到指定路径,当指定路径的业务运行完之后会再返回,接着执型forward 下面的语句};
Redirect:跳转后地址栏发生变化,得不到request中的数据,redirect可以跳到外网路径。Redirect后面的语句会被执行,把servlet中的代码全部执行完才会重定向。
Chain是服务器内部跳转,相当于forward
Action forward到jsp叫做dispatcher
Action forward到action叫做chain
Action redirect到jsp叫做redirect
Action redirect到action叫做redirectaction
<struts>
<constant name="struts.action.extension" value="action,abc,,"></constant>
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.locale" value="zh_CN"></constant>
<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
<package name="default" namespace="/" extends="struts-default">
<action name="a" >
<result type="dispatcher">/index.jsp</result>
</action>//action 内部跳转到jsp
<action name="b">
<result type="redirect">/index.jsp</result>//action重定向跳转到jsp
</action>
<action name="c">
<result type="chain">a</result>//action内部跳转到action
</action>
<action name="d">
<result type="redirectAction">b</result>//action重定向跳转到action
</action>
</package>
</struts>
挎包跳转:
<action name="e">
<result type="redirectAction">
<param name="namespace">/user</param>
<param name="actionName">list</param>
</result>
</action>
</package>
<package name="user" namespace="/user" extends="struts-default">
<action name="list">
<result type="dispatcher">/index.jsp</result>
</action>
</package>
</struts>
全局跳转:
<package name="default" namespace="/" extends="struts-default">
<!-- 全局跳转 -->
<global-results name="error">/error.jsp</global-results>
<action name="a" >
<result type="dispatcher">/index.jsp</result>
</action>
<action name="b">
<result type="redirect">/index.jsp</result>
</action>
<action name="c">
<result type="chain">a</result>
</action>
<action name="d">
<result type="redirectAction">b</result>
</action>
<action name="e">