一、结果(result)类型

result的type属性默认为dispatcher,其他常见的属性有redirect\chain\redirectAction

<action name="a1">
<result type="dispatcher">
/a1.jsp
</result>
</action>
<action name="a2">
<result type="redirect">
/a2.jsp
</result>
</action>
<action name="a3">
<result type="chain">
a1
</result>
</action>
<action name="a4">
<result type="chain">
<param name="actionName">a1</param>
<param name="namespace">/</param>
</result>
</action>
<action name="a5">
<result type="redirectAction">
a1
</result>
</action>

dispatcher就是forward到一个jsp页面

redirect就是跳转到一个jsp页面

chain就是forward到一个action,跳转到另外一个package用第四种方式

redirectAction就是跳转到一个action

二、全局结果集

在配置struts2.xml时有时候会遇到一个问题即多个action的result是相同的这时候就没有必要为每个action配一个result,只要配置一个global result即可:

<package name="index" namespace="/" extends="struts-default">
<global-results>
<result name="msg">/msg.jsp</result>
</global-results>
</package>
<package name="user" namespace="/user" extends="index"> </package>

这样当index包和user包下的action返回msg的时候就会forward到/msg.jsp。(extends="index"从index包继承)

三、动态结果集

在struts.xml中配置:

<action name="login" class="cn.orlion.user.UserAction" method="login">
<result>
${r}
</result>
</action>

UserAction:

package cn.orlion.user;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{

    private int type;

    private String r;

    public String login(){

        if (1 == type) r = "/a1.jsp";
else if (2 == type) r = "/a2.jsp";
return "success";
} public int getType() {
return type;
} public void setType(int type) {
this.type = type;
} public String getR() {
return r;
} public void setR(String r) {
this.r = r;
} }

这样当访问http://localhost:8080/Struts2Demo/user/login.action?type=1时就会看到a1.jsp

访问...?type=2时就会看到a2.jsp了

struts.xml中${r} 实际是从Value Stack中取出r的值

四、结果集传参数

当访问.../login.jsp?uid=test时通过< s:property value="uid" />是取不到的因为uid是个参数不会放到Value Stack中而是放到Stack Context中,可以通过<s:property value="#parameters.uid" />娶到。

当访问一个action(在这个action里赋值给了uid)时,这个action的结果:login.jsp(即forward到 /login.jsp)可以用<s:property value="uid" />取到值,这是因为forward可以从Value Stack中取到。

struts2结果(Result)的更多相关文章

  1. Struts2 配置文件result的name属性和type属性

    Struts2 配置文件result的name属性和type属性:Name属性SUCCESS:Action正确的执行完成,返回相应的视图,success是 name属性的默认值: NONE:表示Act ...

  2. Struts2 中result type属性说明

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

  3. Struts2之Result详解

    上一篇我们把Struts2中的Action接收参数的内容为大家介绍了,本篇我们就一起来简单学习一下Action的4种Result type类型,分为:dispatcher(服务端页面跳转):redir ...

  4. struts2 action result type类型

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

  5. struts2的@Result annotation 如何添加params,并且在页面取值

    http://www.bubuko.com/infodetail-2492575.html .............................................. 标签:lai  ...

  6. Struts2配置Result(Struts2_result)

    一.概要 二.常用四种类型的配置 Struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!D ...

  7. 【struts2】Result和ResultType

    简单的说,Result是Action执行完后返回的一个字符串,它指示了Action执行完成后,下一个页面在哪里.Result仅仅是个字符串,仅仅是用来指示下一个页面的,那么如何才能够到达下一个页面呢? ...

  8. struts2的result的type属性

    一共有两个属性name和type name这里就不介绍了 type    返回结果的类型,值可以从default-struts.properties中看到看到 常用的值:dispatcher (默认) ...

  9. Struts2中 Result类型配置详解

    一个result代表了一个可能的输出.当Action类的方法执行完成时,它返回一个字符串类型的结果码,框架根据这个结果码选择对应的result,向用户输出.在com.opensymphony.xwor ...

  10. Struts2 自定义Result

    注意:我只要是解决自定义返回Json 和异常处理问题 新建一个类 AjaxResult   继承 StrutsResultSupport 看看代码吧 public class AjaxResult e ...

随机推荐

  1. MySql数据源配置

    1.tomcat的config/server.xml中将以下代码写到 </Host>前: <Context docBase="struts1" path=&quo ...

  2. Drupal 7 安装时的数据库问题

    在安装D7时,需要用PhpMyAdmin创建数据库,不建议使用ROOT帐号而需要建立一个新的帐号.一般,建立一个新的账号,如foo,并同时建一个同名的数据库,选择localhost(如果是本地).但是 ...

  3. 二进制求最大公约数&&输出二进制

    Divided Land Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  4. Ubuntu Server 15.04的安装

    U盘启动工具的制作就跟Windows系统以及Linux各版本的desktop版不同,用的工具也是我第一次见到的“Win32_Disk_Imager”(点击下载) 安装过程请参考:http://www. ...

  5. objective-c(反射)

    objective-c中提供类似JAVA的反射特性,给出基本例子如下: #import <Foundation/Foundation.h> @interface ClassA : NSOb ...

  6. 人人都是 DBA(XIV)存储过程信息收集脚本汇编

    什么?有个 SQL 执行了 8 秒! 哪里出了问题?臣妾不知道啊,得找 DBA 啊. DBA 人呢?离职了!!擦!!! 程序员在无处寻求帮助时,就得想办法自救,努力让自己变成 "伪 DBA& ...

  7. 再探@font-face及webIcon制作

    @font-face 不能说他是什么新东西了,在 CSS2.0 规范中就有了这玩意儿,IE4.0 开始就已经出现,只是当时用的不是特别广泛,后来在 CSS2.1 草案中又被删掉.随着 web 的急速发 ...

  8. 谈谈javascript语法里一些难点问题(一)

    1)    引子 前不久我建立的技术群里一位MM问了一个这样的问题,她贴出的代码如下所示: var a = 1; function hehe() { window.alert(a); var a = ...

  9. ECMAScript5的其它新特性

    之前两篇博客 ECMAScript5 Object的新属性方法,ECMAScript5 Array新增方法,分别介绍了ECMAScript5对Object和Array的拓展,这两个对象最常用,而且改动 ...

  10. xamarin UWP平台线程交互问题

    先吐槽一下,xamarin到现在为止,虽然开发一下应用尚可,对于一些简单的app开发使用xamarin-forms方式开发,虽然有一些优势,可以省下开发三个平台共同功能的时间,但是当我们随着项目深入的 ...