在配置result中我们常常使用的是默认的类型,也就是dispatcher。
<result name="success" type="dispatcher">helloWorld.jsp</result>
redirect是重定向的返回类型,即不会带参数返回。
<result name="success" type="redirect">helloWorld.jsp</result>
chain是链条的返回类型,即可实现参数携带到下一个action再次执行。
//将helloWorld.jsp替换成另外action的name即可携带参数执行另一个action
<result name="success" type="chain">helloWorld.jsp</result>
redirectAction则是直接重定向到一个action,无法携带参数。
还有其它不常用的类型在此就不一一赘述,遇到学习即可。
最后介绍一下result的全局配置,即我们配置一个action里面寻找不到result就向上一层寻找的result,这样可以节省在每一个action中配置error的问题。
<struts>
<package name="first" extends="struts-default">
<global-results>
<result name="error">error.jsp</result>
</global-results>
<action name="hello_*" class="com.wood.action.HelloWorld01" method="{1}">
<result name="success" type="dispatcher">helloWorld.jsp</result>
</action>
</package>
</struts>