注:

1.在struts.xml文件中使用include标签 可以将另外一个xml文件包含进struts.xml文件中,如:

 <struts>
<constant name="struts.devMode" value="true" />
<include file="login.xml" />
</struts> //就可以包含login.xml文件

2.可以在struts.xml文件中,使用 <default-action-ref> 标签 来指定默认Action,即找不到对应的Action进行处理时,调用这个Action

  如:<default-action-ref name="index"></default-action-ref>

Result

  1.result 标签  type 属性(用于指定某个Action执行后跳转的方式)

  type = "dispather"(默认) 类似于转发(转发到某个JSP)

  type="redirect" 类似于重定向 (重定向到某个JSP)

  type="chain"  转发到某个Action (转发的Action和自身的Action 不在同一个包下,需要使用参数去指定)

  type="redirectAction" 重定向到某个Action

  这四种需要了解  还有其他的不太常见,重点掌握前面两种

  

  2.全局结果集(<global-results>)

    在某个package中使用<global-results>标签 ,设置全局结果集

    全局结果集的作用:相当于为该package下的每个action 多加上一个result

    如:在Action中,execute方法 既没有返回success,也没有返回error等,返回的是mainpage,

    struts.xml中对应的action 并没有配置 ‘mainpage’ 的result,但如果设置了全局结果集,就仍可以找到对应的result

    注:如果另外一个package,想要使用这个globle results,需要 extends 对应的package,这也是package标签中 extends属性的作用

  3.动态结果(所谓动态:就是在Action中动态指定结果,在struts.xml中再去取出这个结果)

  

 public class UserAction extends ActionSupport {
private int type;
private String result; public void setResult(String result) {
this.result = result;
} public String getResult() {
return result;
} public void setType(int type) {
this.type = type;
} public int getType() {
return type;
} @Override
public String execute() throws Exception {
if(type == 1) {
result="/success.jsp";
} else if(type == 2) {
result="/error.jsp";
}
return SUCCESS;
}
}

  /*不根据result标签中的 name 属性来 进行筛选,而是动态指定想要访问的web资源*/

    1.在Action中,设置一个属性,用于保存动态结果,根据前台传来的信息,来为其赋值

    注意一定不要忘了为动态结果的保存值设置set get方法

    2.在struts.xml 中 取出这个动态结果 使用 ${result}   如:<result> ${result} </result>

  4.带参数的结果集(即返回的web资源路径,后面带有参数,这个参数是Action里面的属性)

 private int type;

 public void setType(int type) {
this.type = type;
} public int getType() {
return type;
}
 <result type="dispatcher"> /success.jsp?t=${type} </result>

   注:

   一次request请求,只有一个值栈 如果result标签中指定类型为 "redirect",重定向到某个Action 或 JSP 那么会有两次请求,

   之前的值栈的内容就无法保存,会被第二次请求覆盖
   如果result标签中指定类型为 "dispather" 转发到某个Action 或JSP 那么请求只有一次,可以共享值栈中的内容

  

3.Struts2-Result的更多相关文章

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

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

  2. Struts2(result 流 )下载

    jsp: <body> <a href="stream.action?fileName=psb.jpg">psb</a> <br> ...

  3. struts2 result type类型

    result标签中type的类型 类型 说明 chain 用于Action链式处理 dispatcher 用于整合JSP,是<result>元素默认的类型 freemarket 用来整合F ...

  4. Struts2 result type(结果类型)

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

  5. Struts2 result type

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

  6. struts2 result的type属性

    目前只使用过以下3种,都是直接跳转到另一个action  chain: 写法:<result name="success" type="chain"> ...

  7. struts2 result type的类型

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

  8. struts2 result type属性说明

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

  9. 分享知识-快乐自己:Struts2 - result标签的name属性和type属性

    1):result的name属性   例如:<result name="success">/pages/success.jsp</result> Strut ...

  10. struts2 result随笔

     一.result:chain(从一个Action转发到另一个Action) chain结果类型有4个属性,分别是: actionName (default) - the name of the ac ...

随机推荐

  1. PCL中有哪些可用的PointT类型(3)

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=268 PointXYZRGBNormal - float x, y, z, ...

  2. Introduction to statistical learning:with Applications in R (书,数据,R代码,链接)

    http://faculty.marshall.usc.edu/gareth-james/ http://faculty.marshall.usc.edu/gareth-james/ISL/

  3. Python之滑动窗口

    需求 对于一个数组array = ["n","v","l","f",...,"y","c& ...

  4. Spring框架是一种非侵入式的轻量级框架

    摘自<Spring框架技术> Spring框架是一种非侵入式的轻量级框架 1.非侵入式的技术体现 允许在应用系统中自由选择和组装Spring框架的各个功能模块,并且不强制要求应用系统的类必 ...

  5. SSD是什么

    SSD即固态硬盘,相较于HDD(机械硬盘),硬件上最主要的区别就是存储介质发生了改变,SSD采用NAND Flash作为存储介质,而HDD采用磁盘作为存储介质.虽然这两种存储介质都是非易失性的,但是他 ...

  6. idea标签页多行显示+设置标签页上限

    idea标签页多行显示+设置标签页上限 Setting--Editor--General--Editor Tabs

  7. 如何申请阿里云免费SSL证书(可用于https网站)并下载下来

    前提条件:你要有阿里云的账号,并且要有一个域名. 注意:阿里云系统也在不断更新,界面以后可能会有稍许变化,但是原理是相通的. 具体步骤: 1.登录到阿里云后台,并选择 “SSL证书(应用安全)” 菜单 ...

  8. 【Abode Air程序开发】Flex air文件打包和运行

    1 安装Adobe AIR 运行时,和java的JVM类似. Adobe AIR 运行时允许在桌面运行AIR应用程序,脱离游览器的束缚. 下载安装文件http://get.adobe.com/cn/a ...

  9. IDEA 2019.2破解激活教程(激活到2089年8月,亲测有效,持续更新中...)

    本来笔者这边是有个正版激活码可以使用的,但是,2019.9月3号的时候,一些小伙伴反映这个注册码已经失效了,于是拿着自己的 IDEA, 赶快测试了一下,果不其然,已然是不能用了. 好在,笔者又找到了新 ...

  10. ZOJ Problem Set - 1003

    1.翻译参考 http://www.cnblogs.com/woodfish1988/archive/2006/11/10/556926.html 2.代码参考 http://www.cnblogs. ...