result标签中type的类型

类型 说明
chain 用于Action链式处理
dispatcher 用于整合JSP,是<result>元素默认的类型
freemarket 用来整合FreeMarket
httpheader 用来处理特殊的HTTP行为
redirect 用来重定向到其它文件
redirectAction 用来重定向到其它Action
stream 用来香浏览器返回一个InputStream
velocity 用来整合Velocity
xslt 用来整合XML/XSLT
plainText 用来显示页面的原始代码

result的type类型定义在struts-default.xml中,定义如下

<package name="struts-default" abstract="true">
<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-type name="postback" class="org.apache.struts2.dispatcher.PostbackResult" />
</result-types>

1.dispatcher结果类型

  dispatcher结果类型用来表示“转发”到指定结果资源,它是struts2的默认结果类型

  (1)建一个test.jsp页面,内容如下:

    <s:form method="post" action="/Login_toLogin">
<s:textfield name="username" label="用户名"/>
<s:password name="password" label="密码"/>
<s:submit></s:submit>
</s:form>

  (2)在src/action下建一个类TestAction

package action;

public class TestAction {

    private String username;
private String password; public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String execute(){
return "success";
}
}

  TestAction类中封装了两个属性username和password

  (3)配置struts.xml文件中action

    <action name="test" class="action.TestAction">
<result type="dispatcher">/testSuccess.jsp</result>
</action>

  (4)新建一个testSuccess.jsp

    用户:<s:property value="username"/><br/>
密码:<s:property value="password"/>

输出结果:

  使用dispatcher记过类型是,由于只是将结果转发到指定资源,所以能够暴力会请求的信息,而且在使用浏览器地址显示为test.action而不是testSuccess.jsp

2、redirect结果类型

  redirect结果类型用来“重定向”,到指定的结果资源,该资源可以是JSP文件,也可以action类。使用redirect结果类型时,系统将调用HttpServletResponse的sendRedirect()方法。

  还是上面的例子,只是在struts.xml中,修改result元素的结果类型为redirect,代码如下:

<action name="test" class="action.TestAction">
<result type="redirect">/testSuccess.jsp</result>
</action>

  结果在url不在test.action,而是testSuccess.jsp。由于redirect使得浏览器再一次发出请求,所有原来的请求资源将不会存在,所以使用<s:property value="username"/>是无法获取到请求数据的

3、stream结果类型

  stream表示流,这种结果类型通常用于实现用户下载文件的Action配置中,参数有:

  (1)contentType:用来指定床底给浏览器stream类型。默认为text/plain

  (2)contentLength:指定数据了的字节长度

  (3)contentDiposition:指定文件下载的处理方式,包括内联(inline)和附件(attachment)这两种方式,内联方式表示浏览器会尝试直接显示文件,附件方式会弹出文件保存对话框,默认值为inline。

  (4)inputName:表示数据了属性。默认值为inputStream

  (5)bufferSize:表示缓冲区容量。默认为1024

struts2 result type类型的更多相关文章

  1. struts2 action result type类型

    struts2 action result type类型 1.chain:用来处理Action链,被跳转的action中仍能获取上个页面的值,如request信息. com.opensymphony. ...

  2. struts2 Result Type四个常用转跳类型

    Result的四个常用转跳类型分别为 Dispatcher 用来转向页面,是Struts的默认形式 Redirect   重定向到一个URL Chain  用来处理Action链 RedirectAc ...

  3. Struts2 result type(结果类型)

    转自:http://www.cnblogs.com/liaojie970/p/7151103.html 在struts2框架中,当action处理完之后,就应该向用户返回结果信息,该任务被分为两部分: ...

  4. struts2 result type的类型

    一共十种类型 1.dispatcher 默认的类型,相当于servlet的foward,服务器端跳转.客户端看到的是struts2中配置的地址,而不是真正页面的地址.一般用于跳转到jsp页面 2.re ...

  5. Struts2 result type

    Struts2支持的不同类型的返回结果为: type name 说明 dispatcher 缺省类型,用来转向页面,通常处理JSP chain 转向另一个action,用来处理Action链 redi ...

  6. struts2 result type属性说明

    首先看一下在struts-default.xml中对于result-type的定义: <result-types><result-type name="chain" ...

  7. Struts2 中result type属性说明

    Struts2 中result type属性说明 首先看一下在struts-default.xml中对于result-type的定义: <result-types><result-t ...

  8. struts2 中的 result 返回类型是 json 的配置问题

    struts2 中的 result 返回类型是 json 的配置问题 1.引入包(本文中的包全部引自struts-2.1.8.1\lib): struts2-json-plugin-2.1.8.1.j ...

  9. Struts2 语法--result type

    result type: dispatcher,redirect:只能跳转到jsp,html之类的页面,dispatcher属于服务器跳转, redirect属于客户端跳转 chain: 等同于for ...

随机推荐

  1. 安卓android破解方法

    韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha  313134555@qq.com 如何给smali文件中的unicode字符串添加中文注释 如何注释掉smali文件中包含关键字 ...

  2. 【贪心】【set】zoj3963 Heap Partition

    贪心地从前往后扫,每到一个元素,就查看之前的元素中小于等于其的最大的元素是否存在,如果存在,就将它置为其父亲.如果一个结点已经是两个儿子的父亲了,就不能在set中存在了,就将他删除.如果然后将当前元素 ...

  3. 【BFS】POJ3669-Meteor Shower

    [思路] 预处理时先将陨石落到各点的最短时间纪录到数组中,然后在时间允许的范围内进行广搜.一旦到某点永远不会砸到,退出广搜. #include<iostream> #include< ...

  4. css样式介绍

    1 css之选择器 1.1 基本选择器 1.2 组合选择器 E,F      多元素选择器,同时匹配所有E元素或F元素,E和F之间用逗号分隔:div,p { color:#f00; } E F     ...

  5. UNIX域套接字连接mysql

    用户可以在配置文件中指定套接字文件的路径,如--socket=/data/mysql/mysql.sock [root@localhost ~]# mysql -uroot -p123456 -S / ...

  6. js 数字键盘

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. Redis-NoSql 概述,NoSql的优点

    全称 not only sql: 全新数据库理念:非关系型数据库: 高并发读写:海量数据的高效率存储和访问:高可扩展性和高可用性: 键值对存储:列存储:文档数据库:图形数据库: 易扩展:灵活的数据模型 ...

  8. express结合jade模板渲染HTML

    在线html转jade工具>> 注意:以下是在Windwo环境下 运行: npm install jade 然后你的目录node_modules下将增加jade文件夹 app.js var ...

  9. IIS_未能映射路径“/”。

      解决方法: 使用托管管道默认是为[经典]的应用程序池

  10. fmri 实验设计 / 范式设计/ paradigm design

    reference:http://www.psychology.gatech.edu/cabi/Resources/Course/index.html sluggish 懒散的,无精打采的.哈哈,pp ...