您的位置:首页 > 编程语言 > Java开发

struts.xml配置文件中action中的result的各种转发类型

2013-10-20 11:18 615 查看
<actionname="helloworld"class="cn.itcast.action.HelloWorldAction">

<result name="success">/WEB-INF/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在别的命名空间下:

<result type="redirectAction">

<paramname="actionName">helloworld</param>

<paramname="namespace">/test</param>

</result>

plaintext:显示原始文件内容,例如:当我们需要原样显示jsp文件源代码的时候,我们可以使用此类型。

<result name="source" type="plainText">

<paramname="location">/xxx.jsp</param>

<paramname="charSet">UTF-8</param> <!--
指定读取文件的编码 -->

</result>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐