struts2结果(Result)
一、结果(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)的更多相关文章
- Struts2 配置文件result的name属性和type属性
Struts2 配置文件result的name属性和type属性:Name属性SUCCESS:Action正确的执行完成,返回相应的视图,success是 name属性的默认值: NONE:表示Act ...
- Struts2 中result type属性说明
Struts2 中result type属性说明 首先看一下在struts-default.xml中对于result-type的定义: <result-types><result-t ...
- Struts2之Result详解
上一篇我们把Struts2中的Action接收参数的内容为大家介绍了,本篇我们就一起来简单学习一下Action的4种Result type类型,分为:dispatcher(服务端页面跳转):redir ...
- struts2 action result type类型
struts2 action result type类型 1.chain:用来处理Action链,被跳转的action中仍能获取上个页面的值,如request信息. com.opensymphony. ...
- struts2的@Result annotation 如何添加params,并且在页面取值
http://www.bubuko.com/infodetail-2492575.html .............................................. 标签:lai ...
- Struts2配置Result(Struts2_result)
一.概要 二.常用四种类型的配置 Struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!D ...
- 【struts2】Result和ResultType
简单的说,Result是Action执行完后返回的一个字符串,它指示了Action执行完成后,下一个页面在哪里.Result仅仅是个字符串,仅仅是用来指示下一个页面的,那么如何才能够到达下一个页面呢? ...
- struts2的result的type属性
一共有两个属性name和type name这里就不介绍了 type 返回结果的类型,值可以从default-struts.properties中看到看到 常用的值:dispatcher (默认) ...
- Struts2中 Result类型配置详解
一个result代表了一个可能的输出.当Action类的方法执行完成时,它返回一个字符串类型的结果码,框架根据这个结果码选择对应的result,向用户输出.在com.opensymphony.xwor ...
- Struts2 自定义Result
注意:我只要是解决自定义返回Json 和异常处理问题 新建一个类 AjaxResult 继承 StrutsResultSupport 看看代码吧 public class AjaxResult e ...
随机推荐
- ILSpy搜索功能加强版
1.修改搜索功能,增加如下的额外搜索选项 A.按文本搜索(默认选项) B.按通配符搜索 C.按正则表达式搜索 2.搜索增加如下特性: A.可以按照名字空间检索特定名字空间下的所有类. B.修正了官方版 ...
- 未能从程序集“System.ServiceModel, Version=3.0.0.0问题解决
在Windows Server 2008中的IIS服务器中部署WCF服务程序时,通过浏览器访问报出如下错误: 未能从程序集“System.ServiceModel, Version=3.0.0.0, ...
- ubuntu上搭建review board代码评审站点
Reviewboard是一个开源个人可以免费使用的代码评审框架,貌似现在有越来越多的公司也开始使用reviewboard作为公司的代码评审工具. 今天早上试了一下,搭建过程非常方便简单,按照网页提示即 ...
- java-IO
框架图 IO(Input Output)流IO流用来处理设备之间的数据传输,Java对数据的操作是通过流的方式,用于操作流的对象都在IO包中. 流按操作数据分为两种:字节流与字符流 .流按流向分为:输 ...
- hdu 5719(Arrange)(冷静分析)
A数组显示从0到i的最小值B数组显示从0到i的最大值由此可得:A数组是单调不增的(怎么也会不使得最小值变大)B数组是单调不减的.设premin和premax为i位以前的最小值和最大值.可以得出以下几点 ...
- Linux内核--网络栈实现分析(八)--应用层发送数据(下)
本文分析基于Linux Kernel 1.2.13 原创作品,转载请标明http://blog.csdn.net/yming0221/article/details/7547826 更多请查看专栏,地 ...
- caffe 在window下编译(windows7, cuda8.0,matlab接口编译)
1. 环境:Windows7,Cuda8.0,显卡GTX1080,Matlab2016a,VS2013 (ps:老板说服务器要装windows系统,没办法,又要折腾一番,在VS下编译好像在cuda8. ...
- [leetcode 37]sudoku solver
1 题目: 根据给出的数独,全部填出来 2 思路: 为了做出来,我自己人工做了一遍题目给的数独.思路是看要填的数字横.竖.子是否已经有1-9的数字,有就剔除一个,最后剩下一个的话,就填上.一遍一遍的循 ...
- php+mysql+apache+nginx
http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 安装mysql rpm -qa | grep mysql ...
- 如何安全地关闭MySQL实例
如何安全地关闭MySQL实例 转载自:http://imysql.com/2014/08/13/mysql-faq-howto-shutdown-mysqld-fulgraceful.shtml 本文 ...