Structs2的结果类型
来源:互联网 发布:战网传输数据遇到异常 编辑:程序博客网 时间:2024/06/04 23:24
<转载>+修改
在struts2-core-xxx.jar根目录下的struts-default.xml中配置了struts2提供的一系列结果类型
struts2的结果类型实现了com.opensymphony.xwork2.Result接口
<result-types>
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
</result-types>
type支持的结果类型:
chain:用来处理Action链
dispatcher:用来转向页面,通常处理JSP
freemaker:处理FreeMarker模板
httpheader:控制特殊HTTP行为的结果类型
redirect:重定向到一个URL
redirectAction:重定向到一个Action
stream:向浏览器发送InputSream对象,通常用来处理文件下载,还可用于返回AJAX数据
velocity:处理Velocity模板
xslt:处理XML/XLST模板
plaintext:显示原始文件内容,例如文件源代码
dispatcher 结果类型为缺省的result类型,用于返回一个视图资源(如:jsp)
Xml代码 :
<result name="success">/main.jsp</result>
以上写法使用了两个默认,其完整的写法为:
<result name="success" type="dispatcher">
<param name="location">/main.jsp</param>
</result>
location只能是页面,不能是另一个action(可用type="chain"解决)。
redirect 结果类型用于重定向到一个页面,另一个action或一个网址。
Xml代码:
- <result name="success" type="redirect">aaa.jsp</result>
- <result name="success" type="redirect">bbb.action</result>
- <result name="success" type="redirect">www.baidu.com</result>
redirect-action 结果类型使用ActionMapperFactory提供的ActionMapper来重定向请求到另外一个action
Xml代码:
- <result name="err" type="redirect-action">
- <param name="actionName">重定向的Action名</param>
- <param name="namespace">重定向Action所在的名字空间</param>
- </result>
如果想在action之间进行传值,则代码如下:
- <action name="saveExhibitionAppTable"
- class="cn.gov.tdb.controller.EnterpriseController"
- method="saveExhibitionAppTable">
- <result name="input">exhibitionAppTable.jsp</result>
- <result name="success" type="redirect-action">
- <param name="actionName">generateBarcode</param>
- <param name="namespace"></param>
- <param name="getTichetSource">${getTichetSource}</param>
- <param name="companyId">${companyId}</param>
- <param name="serviceId">${serviceId}</param>
- </result>
- action>
redirect和redirect-action两种结果类型在使用上其实并没有什么区别,只是写法不同而已。
chain 用于把相关的几个action连接起来,共同完成一个功能。
Xml代码:
- <action name="step1" class="test.Step1Action">
- <result name="success" type="chain">step2.action</result>
- </action>
- <action name="step2" class="test.Step2Action">
- <result name="success">finish.jsp</result>
- </action>
处于chain中的action属于同一个http请求,共享一个ActionContext
plaintextj 结果类型用于直接在页面上显示源代码
Xml代码:
- <result name="err" type="plaintext">
- <param name="location">具体的位置</param>
- <param name="charSet">字符规范(如GBK)</param>
- </result>
- Structs2的结果类型
- Structs2 的Result 类型
- structs2 DefaultTypeConverter类型转换说明
- 【web开发学习笔记】Structs2 Result学习笔记(三)带参数的结果集
- structs2 文件的上传下载
- structs2 的工作原理
- structs2的工作流程
- structs2 投影的介绍
- structs2的工作原理
- structs2的一些理解
- structs2的运行机制
- structs2
- Structs2
- structs2
- structs2
- structs2
- struts2的result结果类型
- struts2的result结果类型
- linux下面简单通用的Makefile模板
- Program1-1
- linux中export用法
- 免费的编程中文书籍索引
- C语言经典算法100例004
- Structs2的结果类型
- pyton 字符串、list
- C语言经典算法100例005
- Android开发技巧——PagerAdapter的再次简单封装
- 调试QML应用
- Micron与AllianceMemory的合作声明
- JDK 1.5新特性
- C语言经典算法100例006
- smartSVN的使用