<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。
在result中还可以使用${属性名}表达式访问action中的属性,表达式里的属性名对应action中的属性。如下:
<result type="redirect">/view.jsp?id=${id}</result>
下面是redirectAction 结果类型的例子,如果重定向的action中同一个包下:
<result type="redirectAction">helloworld</result>
如果重定向的action在别的命名空间下:
<!-- actionName 这个参数名可以再struts-default.xml <result-types>找到先对应的了类-->
<result type="redirectAction">
<!-- actionName 这个参数名可以再org.apache.struts2.dispatcher.ServletActionRedirectResult-->
<!--这是通过反射机制来注入属性值-->
<param name="actionName">helloworld</param>
<param name="namespace">/test</param>
</result>
plaintext显示原始文件内容,例如:当我们需要原样显示jsp文件源代码 的时候,我们可以使用此类型。
<result name="source" type="plainText ">
<!--这是通过反射机制来注入属性值-->
<param name="location">/xxx.jsp</param>
<param name="charSet">UTF-8</param><!-- 指定读取文件的编码 -->
</result>size=xx-small]
Action中result的各种转发类型
原创
©著作权归作者所有:来自51CTO博客作者青年IT男1的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Intent中各种常见的Action
Intent中各种常见的Action
Intent中各种常见的Action -
struts2之Action配置的各项默认值、result配置的各种试图转发类型及为应用指定多个struts配置文件
1、Action配置的各项默认值(1)、如果没有为action指定class,默认是ActionSupport。(2)、如果没有为action指定method,默认执行action中的execute()方法。(3)、如果没有为action指定result,默认值为success。 2、result配置的各种试图转发类型<result type="">...</result
struts2 多个struts配置文件 result配置的各种试图转发类型 Action配置的各项默认值 struts xml