一:关于Struts2的type类型,也就是Result类型,他们都实现了共同的接口Result,都实现了execute方法
他们体现了策略模式,具体Result类型参见:struts-default.xml文件:
 <result-types>
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
</result-types>
我们完全可以自己根据需求扩展Result类型
 
二:在Struts2中默认为转发,也就是<result>标签中的type="dispatcher",type的属性可以修改为重定向
Struts的重定向有两种:
type="redirect",可以重定向到任何一个web资源,如:jsp或Action,如果要重定向到Action,需要写上后缀:xxxx.action
type="redirectAction",可以重定向到Action,不需要写后缀,此种方式更通用些,不会因为后缀的改变影响配置
 
三:<result>标签的name属性,如果不配置,那么缺省值为success
 
四:全局Result和局部Result
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd"> <struts> <!-- 当struts.xml配置文件发生修改,会立刻加载,在生产环境下最好不要配置 -->
<constant name="struts.configuration.xml.reload" value="true"></constant>
<!-- 提供更加友好的提示信息 -->
<constant name="struts.devMode" value="true"></constant>
<!-- 对字符集的设置 -->
<constant name="struts.i18n.encoding" value="GB18030"/> <package name="struts2" extends="struts-default">
<!-- 全局Result,如果Action没有配置Result,使用全局Result,如果有局部Result,使用局部Result -->
<global-results>
<result>/success.jsp</result>
<result name="error">/error.jsp</result>
</global-results>
<action name="login" class="com.djoker.struts2.LoginAction">
<result>/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package> <include file="struts-user.xml"></include>
</struts>

struts2学习笔记之七:Result类型的更多相关文章

  1. Struts2 学习笔记 11 Result part2

    之前学习了result type 和global result 我们现在来说一下 1.Dynamic Result动态结果集.先来看一下小项目的目录 首页的两个链接访问user/user?type=1 ...

  2. Struts2学习笔记(四)——result结果类型

    当Action类的方法处理请求后,会返回一个字符串(逻辑视图名),框架根据这个结果码选择对应的result,向用户输出,所以需要在struts.xml提供<result>元素定义结果页面, ...

  3. Struts2学习笔记(三):result配置的各项视图转发类型

    Struts 1: <action path="/user" type="org.sunny.user.action.UserAction" ...> ...

  4. Struts2 学习笔记 10 Result部分 part1

    1.关于Result我们首先来学习一下结果类型 result type. 先来看struts.xml. struts.xml <?xml version="1.0" enco ...

  5. Struts2学习笔记⑧

    今天是Struts2学习笔记的最后一篇文章了.用什么做结尾呢,这两天其实还学了很多东西,没有记录下,今天就查漏补缺一下. 文件上传与下载.FreeMarker以及昨天没做完的例子 文件上传与下载 文件 ...

  6. Struts2 学习笔记(概述)

    Struts2 学习笔记 2015年3月7日11:02:55 MVC思想 Strust2的MVC对应关系如下: 在MVC三个模块当中,struts2对应关系如下: Model: 负责封装应用的状态,并 ...

  7. Hadoop学习笔记—5.自定义类型处理手机上网日志

    转载自http://www.cnblogs.com/edisonchou/p/4288737.html Hadoop学习笔记—5.自定义类型处理手机上网日志 一.测试数据:手机上网日志 1.1 关于这 ...

  8. Struts2学习笔记①

    Struts2 学习笔记① 所有的程序学习都从Hello World开始,今天先跟着书做一个HW的示例. Struts2是一套MVC框架,使用起来非常方便,接触到现在觉得最麻烦的地方是配置文件.我的一 ...

  9. Struts2学习笔记NO.1------结合Hibernate完成查询商品类别简单案例(工具IDEA)

    Struts2学习笔记一结合Hibernate完成查询商品类别简单案例(工具IDEA) 1.jar包准备 Hibernate+Struts2 jar包 struts的jar比较多,可以从Struts官 ...

随机推荐

  1. javascript typeof

    https://zhidao.baidu.com/question/79159257.html typeof 运算符返回一个用来表示表达式的数据类型的字符串. 可能的字符串有:"number ...

  2. LinkList(JAVA版,contain rear)

    //含有rear,尾插时时O(1)的复杂度package linearList;//凡是实现后插后删都比较容易,尽量向着这个方向转换public  class linearList {      cl ...

  3. iOS 应用中有页面加载gif动画,从后台进入前台时就消失了

    解决办法: 在Appdelegate.m 里面有一个从后台进入前台所响应的方法,可以在该方法里post 一个通知,在加载动画里的页面接受通知,响应一定的方法即可 #pragma -mark 当程序进入 ...

  4. 使用doxygen制作C代码文档

    使用doxygen制作C代码文档 C 代码注释风格约定 行间注释 /*! * * 这里是注释 * */ 行内注释 <code here> /*! 这里是注释 */ doxygen 风格的宏 ...

  5. 如何将动态生成Word文件

    大致的思路是先用office2003或者2007编辑好Word的样式,然后另存为XML,将XML翻译为FreeMarker模板,最后用Java来解析FreeMarker模板并输出Doc.经测试这样方式 ...

  6. localStorage, localforage, web sql三者的比较

    最近的项目中用到了前端存储,最初选用的是localStorage,这个是html5里面新增的API,用法很简单.setItem getItem clear. 值得注意的是,localStorage中存 ...

  7. shell选择语句

    if语句 1) if ... else 语句 if ... else 语句的语法: if [ expression ] then Statement(s) to be executed if expr ...

  8. 字符串流stringstream(头文件sstream)

    今天看到一样很有趣的东西,可以用于各种类型的转换.其实一个文本可以看作一个长长的字符串,整数啊浮点数的都是字符串,于是在字符串流里面就可以很方便地玩转各种类型,比如说: #include<ios ...

  9. 如何给澳洲路局写信refound罚金,遇到交通罚款怎么办

    在澳洲,100%的司机收到过罚单,包括停车,超速,闯红灯等等,其罚金一般都在200-500之间,当然其单位是AUD.所以,对大多数留学生来说,收到罚金意味着一个礼拜要吃吐了. 本人就收到过一次超速罚单 ...

  10. 基于AutoCAD的ObjectARX之NET扩展(mcnetarx)-AcdbEntNext、AcdbEntLast

    1.AcdbEntLast用于获取最后一个创建的实体. 2.AcdbEntNext用于获取指定实体名称之后的下一个创建的实体. ' 定义保存实体名称的变量 Dim ent() As Integer = ...