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. Memory Allocation with COBOL

    Generally, the use of a table/array (Static Memory) is most common in COBOL modules in an applicatio ...

  2. grunt-contrib-qunit安装过程中phantomjs安装报错问题解决

    今天自己fork了一个github上别人写的一个关于grunt项目的一个小demo(https://github.com/cowboy/jquery-tiny-pubsub),主要是想学习下grunt ...

  3. [Codeforces #196] Tutorial

    Link: Codeforces #196 传送门 A: 枚举 #include <bits/stdc++.h> using namespace std; #define X first ...

  4. Problem B: 年龄问题

    #include<stdio.h> int xx(int n,int m,int k) { int a; ) { a=k; } else { a=xx(n-,m,k)+m; } retur ...

  5. [典型漏洞分享]Insert型SQL注入的发现和利用,篡改订单金额

    本例中的SQL注入和其它发现的SQL注入的主要区别:1.生成订单接口是一次性的,反复提交无效,因此,此类型的SQL注入比较难通过扫描器发现,需要人工提取和手动测试.2.Insert类型的SQL注入,不 ...

  6. Microsoft SQL Server 2012 Internals

    http://blog.csdn.net/column/details/learnsqlserver2012.html

  7. location和history

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. Active Snake (Level Set 模型)

    前沿:最近由于大论文实验的原因,需要整理几种Snake方法,以比较道路提取效果.所以今天晚上就将电脑中的一些LBF Snake代码作一下分类定义.并给出效果.以便比较. 1. 原始的LBF Snake ...

  9. 【docker】【redis】2.docker上设置redis集群---Redis Cluster部署【集群服务】【解决在docker中redis启动后,状态为Restarting,日志报错:Configured to not listen anywhere, exiting.问题】【Waiting for the cluster to join...问题】

    参考地址:https://www.cnblogs.com/zhoujinyi/p/6477133.html https://www.cnblogs.com/cxbhakim/p/9151720.htm ...

  10. Netty游戏服务器二

    上节我们写个server主类,那么发现什么事情都干不了,是的,我们还没有做任何的业务处理. 接着我们开始写处理客户端连接,发送接收数据的类ServerHandler. public class Ser ...