<Action>中<result>的各种转发类型
2012-10-04 23:19
274 查看
<result>标签中的type属性决定如何处理客户端的请求:
result配置类似于struts1中的forward,但struts2中提供了多种结果类型,常用的类型有: dispatcher(默认值)、 redirect 、 redirectAction 、 plainText。
(1)dispatcher 转发 (地址栏不会变)
(2)redirect 重定向,重定向的url不能是WEB-INF目录下的资源 (地址栏会变)
(3)redirectAction 重定向到本package或其他package的action处理。(地址栏会变)
(4)plainText 将资源文件源文件输出到客户端(地址栏不会变)
(1)dispatcher
(缺省值)
<action name="helloworld" class="cn.itcast.action.HelloWorldAction">
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
(2)redirect
在result中还可以使用${属性名}表达式访问action中的属性,表达式里的属性名对应action中的属性。如下:
<result type="redirect">/view.jsp?id=${id}</result>
(3)redirectAction
下面是redirectAction 结果类型的例子,如果重定向的action在同一个命名空间下:
<result type="redirectAction">helloworld</result>
如果重定向的action在别的命名空间下:
<action name="regist">
<result type="redirectAction">
<param name="actionName">helloAction</param>
<!-- 如果是同一个命名空间,则可以不要下面的参数 -->
<param name="namespace">/test</param>
<!-- 如果不配method参数 ,则method值是actionName参数对应的method-->
<param name="method">execute</param>
</result>
</action>
(4)plaintext:显示原始文件内容,例如:当我们需要原样显示jsp文件源代码 的时候,我们可以使用此类型。
<result name="source" type="plainText ">
<param name="location">/xxx.jsp</param>
<param name="charSet">UTF-8</param><!-- 指定读取文件的编码 -->
</result>
result配置类似于struts1中的forward,但struts2中提供了多种结果类型,常用的类型有: dispatcher(默认值)、 redirect 、 redirectAction 、 plainText。
(1)dispatcher 转发 (地址栏不会变)
(2)redirect 重定向,重定向的url不能是WEB-INF目录下的资源 (地址栏会变)
(3)redirectAction 重定向到本package或其他package的action处理。(地址栏会变)
(4)plainText 将资源文件源文件输出到客户端(地址栏不会变)
(1)dispatcher
(缺省值)
<action name="helloworld" class="cn.itcast.action.HelloWorldAction">
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
(2)redirect
在result中还可以使用${属性名}表达式访问action中的属性,表达式里的属性名对应action中的属性。如下:
<result type="redirect">/view.jsp?id=${id}</result>
(3)redirectAction
下面是redirectAction 结果类型的例子,如果重定向的action在同一个命名空间下:
<result type="redirectAction">helloworld</result>
如果重定向的action在别的命名空间下:
<action name="regist">
<result type="redirectAction">
<param name="actionName">helloAction</param>
<!-- 如果是同一个命名空间,则可以不要下面的参数 -->
<param name="namespace">/test</param>
<!-- 如果不配method参数 ,则method值是actionName参数对应的method-->
<param name="method">execute</param>
</result>
</action>
(4)plaintext:显示原始文件内容,例如:当我们需要原样显示jsp文件源代码 的时候,我们可以使用此类型。
<result name="source" type="plainText ">
<param name="location">/xxx.jsp</param>
<param name="charSet">UTF-8</param><!-- 指定读取文件的编码 -->
</result>
相关文章推荐
- <!-- <s:action name="navAllFront" namespace="/nav" executeResult="true" flush="false"></s:action>
- Struts2通配符映射/Struts <action name="/*/*" method="{2}" class="com.jxc.action.{1}Action"> <result
- <Action>和<result>配置中的各项默认值
- <input type="file" />浏览时只显示指定文件类型
- &lt;s:iterator&gt;各种遍历用法
- Struts2中的<s:action>标签
- struts2之Action配置的各项默认值、result配置的各种试图转发类型及为应用指定多个struts配置文件
- struts2之Action配置的各项默认值、result配置的各种视图转发类型及为应用指定多个struts配置文件
- <Machine Learning in Action >之二 朴素贝叶斯 C#实现文章分类
- <<web>>css3 各种平面图形的绘制(转)
- &lt;展现C#&gt;第四章C#类型
- 2.Struts的<action input=""></action>:ActionForm
- <<探讨linux/unix>>之文件类型
- struts.xml配置文件中action中的result的各种转发类型
- <s:action>标签
- zoj3819Average Score 类型转化 <求大于1个(double)数的整数,小于1个double类型的数的整数>
- Action中result的各种转发类型:
- Struts2:Action中result的各种转发类型
- <PY><core python programming笔记>C7 字典和集合类型
- <Js>数据类型