<action name="helloworld" class="cn.itcast.action.HelloWorldAction">
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
result配置类似于struts1中的forward,但struts2中提供了多种结果类型,如: dispatcher(默认值)、 redirect 、 redirectAction 、 plainText。
1)下面是redirectAction 结果类型的例子,如果重定向的action中同一个包下:
<result type="redirectAction">helloworld</result>
如果重定向的action在别的命名空间下:
<result type="redirectAction">
<param name="actionName">helloworld</param>
<param name="namespace">/test</param>
</result>
2) 如果没有指定result的name属性,默认值为success。
3) 在result中还可以使用${属性名}表达式,表达式里的属性名对应action中的属性。如下:
<result type="redirect">view.jsp?id=${id}</result>
Struts2 在Struts.xml配置Action的result
最新推荐文章于 2019-07-31 21:37:00 发布