一、结果(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. <Oracle Database>物理结构

    物理结构 Oracle物理结构包含了数据文件.日志文件和控制文件 数据文件 每一个Oracle数据库有一个或多个物理的数据文件.一个数据库的数据文件包含全部数据库数据.数据文件有下列特征: 一个数据文 ...

  2. TCL:表格(xls)中写入数据

    intToChar.tcl # input a number : 1 to 32 , you will get a char A to Z #A-Z:1-32 proc intToChar {int} ...

  3. ASP.Net的导出Excel的快速方法,DataTable导出Excel(亲测,非原创)

    //使用方法 ExcelHelper.dataTableToCsv(dt,@"D:\1212.xls");System.Diagnostics.Process.Start(@&qu ...

  4. 界面显示两个ListView

    1.List界面布局 <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:an ...

  5. JavaScript 基础第二天

    一.前言 感觉昨天的内容确实是有点细碎.复杂.感觉是没有书上写的那么的细致而且有导入性,但是我还是喜欢这样只说干货.今天的内容将继续接着昨天最后的内容JS中的语言结构继续讲解并且重点讲解一下其中的内容 ...

  6. QQ在线客服设置

    QQ在线客服设置 1.客户在添加QQ在线客服后,需要让用户在线不需要添加为好友就能在线对话,一般默认设置下会显示"您需要添加对方为好友+才能给对方发送会话消息",具体解决方法如下: ...

  7. 使用knockout-sortable实现对自定义菜单的拖拽排序

    在开始之前,照例,我们先看效果和功能实现. 关于自定义菜单的实现,这里就不多说了,需要了解的请访问:http://www.cnblogs.com/codelove/p/4838766.html 这里需 ...

  8. Lucene 查询工具 LQT

    Lucene Query Tool (lqt) 是一个命令行工具用来执行 Lucene 查询并对结果进行格式化输出. 使用方法: 01 $ ./lqt 02 usage: LuceneQueryToo ...

  9. Invalidate,Update与Refresh的区别

    在做Windows Forms开发的时候,免不了需要手动刷新窗口,以重绘所需更改的控件,或其它什么的.当出现这类需求时,你有三个选择,使用Invalidate,Update或者Refresh方法. I ...

  10. ie8下使用knockoutjs遇到的一个模板异常

    ViewModel中有一个数组,代码大概如下: function ReportViewModel(){ var self = this; self.extendedProperties = ko.ob ...