result-type的几种常见使用方法
2012-11-30 22:12
591 查看
当初搞jsp开发的时候,就有点搞不懂那神乎其神的各种页面跳转、转发。struts2中把这类页面操作进行了分类封装,特整理,记录如下。
在默认时,<result>标签的type属性值是“dispatcher”(实际上就是转发,forward)。开发人员可以根据自己的需要指定不同的类型,如redirect、stream等。如下面代码所示:
这此result-type可以在struts2-core-2.0.11.1.jar包或struts2源代码中的struts-default.xml文件中找到,在这个文件中找到<result-types>标签,所有的result-type都在里面定义了。代码如下:
com.opensymphony.xwork2.ActionChainResult
org.apache.struts2.dispatcher.ServletDispatcherResult
org.apache.struts2.views.freemarker.FreemarkerResult
org.apache.struts2.dispatcher.HttpHeaderResult
org.apache.struts2.dispatcher.ServletRedirectResult
org.apache.struts2.dispatcher.ServletActionRedirectResult
org.apache.struts2.dispatcher.StreamResult
org.apache.struts2.dispatcher.VelocityResult
org.apache.struts2.views.xslt.XSLTResult
org.apache.struts2.dispatcher.PlainTextResult
org.apache.struts2.dispatcher.ServletActionRedirectResult
org.apache.struts2.dispatcher.PlainTextResult
在默认时,<result>标签的type属性值是“dispatcher”(实际上就是转发,forward)。开发人员可以根据自己的需要指定不同的类型,如redirect、stream等。如下面代码所示:
<result name="save" type="redirect"> /result.jsp </result>
这此result-type可以在struts2-core-2.0.11.1.jar包或struts2源代码中的struts-default.xml文件中找到,在这个文件中找到<result-types>标签,所有的result-type都在里面定义了。代码如下:
<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" /> <!-- Deprecated name form scheduled for removal in Struts 2.1.0. The camelCase versions are preferred. See ww-1707 --> <result-type name="redirect-action" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/> <result-type name="plaintext" class="org.apache.struts2.dispatcher.PlainTextResult" /> </result-types>
chain
用来处理Action链com.opensymphony.xwork2.ActionChainResult
dispatcher
用来转向页面,通常处理JSPorg.apache.struts2.dispatcher.ServletDispatcherResult
freemaker
处理FreeMarker模板org.apache.struts2.views.freemarker.FreemarkerResult
httpheader
控制特殊HTTP行为的结果类型org.apache.struts2.dispatcher.HttpHeaderResult
redirect
重定向到一个URLorg.apache.struts2.dispatcher.ServletRedirectResult
redirectAction
重定向到一个Actionorg.apache.struts2.dispatcher.ServletActionRedirectResult
stream
向浏览器发送InputSream对象,通常用来处理文件下载,还可用于返回AJAX数据org.apache.struts2.dispatcher.StreamResult
velocity
处理Velocity模板org.apache.struts2.dispatcher.VelocityResult
xslt
处理XML/XLST模板org.apache.struts2.views.xslt.XSLTResult
plainText
显示原始文件内容,例如文件源代码org.apache.struts2.dispatcher.PlainTextResult
redirect-action
重定向到一个Actionorg.apache.struts2.dispatcher.ServletActionRedirectResult
plaintext
显示原始文件内容,例如文件源代码org.apache.struts2.dispatcher.PlainTextResult
相关文章推荐
- jQuery $.each()常见的几种使用方法
- win8系统下使用管理员权限运行CMD的几种常见方法
- [置顶] ckeditor 的几种使用方法总结(附演示工程文件,并且解决几个常见错误)
- ckeditor 的几种使用方法总结(附演示工程文件,并且解决几个常见错误)
- 框架嵌套iframe标签常见的几种使用方法
- iframe标记常见的几种使用方法
- 先序,中序,后序,求叶子结点数,深度,拷贝,几种二叉树的常见递归使用方法
- AlertDialog 的几种常见使用方法
- 使用WireShark分析HTTP协议时几种常见的汉字编码及其解码方法小结
- 【Android】31、常见控件的使用方法——ProgressBar
- java 枚举的常见使用方法
- android toast几种使用方法 toast经常会用到,今天做个总结
- Hadoop使用常见问题以及解决方法
- Linux常见的几种加固方法
- SSH笔记-result标签中type的使用
- 用javah 导出类的头文件, 常见的错误及正确的使用方法
- Android中的onActivityResult和setResult方法的使用
- Android中的onActivityResult和setResult方法的使用
- iOS中常见的几种加密方法总结
- 转载:ResultMap和ResultType在使用中的区别