注:

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. Django URL调度器

    Django处理请求的流程 Django确定要使用的根URLconf模块.通常,这是ROOT_URLCONF设置的值,但如果传入 HttpRequest对象具有urlconf 属性(由中间件设置),则 ...

  2. spark的RDD如何转换为DataFrame

    1.Dataset与RDD之间的交互 Spark仅支持两种方式来将RDD转成Dataset.第一种方式是使用反射来推断一个RDD所包含的对象的特定类型.这种基于反射的方式会让代码更加地简洁,当你在编写 ...

  3. 代码托管至Github

    昨天突然之间觉得作为一个iOS程序员,没有在github上提交过自己的代码真是一大遗憾,不管是自己写的优秀的代码还是刚开始学习,用来学习练手的项目.然后我就很想要学习怎么往github上提交代码,很不 ...

  4. rocksdb wiki文档阅读笔记

    由于是英文文档,不做笔记过一阵就忘了,现在把关键点记录到这,开发的时候使用. 具体wiki地址:https://github.com/facebook/rocksdb/wiki 1)Column Fa ...

  5. 树莓派使用c语言控制管脚--wiringPi安装

    树莓派先安装git,然后安装库 命令如下 git clone https://github.com/WiringPi/WiringPi cd wiringPi ./build 测试--输出管脚信息 g ...

  6. flask 之(七) --- 认证|文件|部署

    登陆注册 说明: 令牌Token认证,在对HTTP形式的API发请求时,大部分情况我们不是通过用户名密码做验证,而是通过一个令牌[Token来做验证]. RESTful API无法使用Flask-Lo ...

  7. centos 自动挂载ISO

    创建挂载点并挂载光盘mkdir -p /media/cdrommount -t iso9660 -o loop /usr/ison/centos.iso /media/cdrom 设置开机自动挂载:方 ...

  8. 【Abode Air程序开发】移动设备、桌面和浏览器应用程序开发的差异

    移动设备.桌面和浏览器应用程序开发的差异 在移动设备应用程序中使用 Spark 和 MX 组件的限制 移动设备应用程序在性能方面的注意事项 浏览器  将应用程序部署为 SWF 文件,以用于在浏览器中运 ...

  9. 【VS开发】【DSP开发】WinDriver简介(或介绍)

    WinDriver for Windows简化并自动化了用户模式Windows设备驱动程序的开发,支持设备包括PCI / CardBus / ISA/ PCI-104 / PCMCIA * / PMC ...

  10. [转帖]AARRR已是过去式,而RARRA才是更好的增长黑客模型

    AARRR已是过去式,而RARRA才是更好的增长黑客模型 管理.该方法论已成为了企业家创业的增长利器.但现在看来,AARRR已是过去式. http://www.woshipm.com/operate/ ...