action调用处理之后,向用户呈现一个结果视图, 这个些视图是由不同结果类型来管理的,结果类型实现了
com.opensymphony.xwork2.Result 接口
预定义的结果类型由:
在struts2-core-2.0.11.2.jar根目录下的struts-default.xml中配置了struts2提供的一系列结果类型
struts2的结果类型实现了com.opensymphony.xwork2.Result接口
type支持的结果类型:
- * chain:用来处理Action链
- chart:整合JFreeChart的结果类型
- * dispatcher:用来转向页面,通常处理JSP
- * freemaker:处理FreeMarker模板
- httpheader:控制特殊HTTP行为的结果类型
- jasper:用于JasperReports整合的结果类型
- jsf:JSF整合的结果类型
- * redirect:重定向到一个URL
- * redirect-action:重定向到一个Action
- stream:向浏览器发送InputSream对象,通常用来处理文件下载,还可用于返回AJAX数据
- tiles:与Tiles整合的结果类型
- velocity:处理Velocity模板
- xslt:处理XML/XLST模板
- plaintext:显示原始文件内容,例如文件源代码
<action name="actionName" class="package.ActionName"> <result name="逻辑视图名" type="视图结果类型"/> <param name="参数名">参数值</param> name属性可以为以下两个值: ·location:参数指定逻辑视图 ·parse:是否允许在实际视图名中使用OGNL表达式。参数默认为true; 实际上通常不需要明确写这个param标签,而是直接在<result></result>中指定物理视图位置 </result> 属性细节: name:逻辑视图名,若无指定,默认为success type:指定视图结果类型,默认为dispatcher(即jsp),可以通过对参数的修改改变默认视图结果类型 </action>
parse 是个布尔型, 如果为ture 就解析location参数的OGNL表达式
个需要注意的结果类型:
- plaintext结果类型直接在页面上显示源代码
可以为其设置编码
- <result name="err" type="plaintext">
- <param name="location">具体的位置</param>
- <param name="charSet">字符规范(如GBK)</param>
- </result>
- redirect结果类型将请求重定向到指定的视图资源,将会丢失所有的请求参数、请求熟悉及Action的处理结果
- <result name="err" type="redirect">具体的位置</result>
- redirect-action结果类型使用ActionMapperFactory提供的ActionMapper来重定向请求
- <result name="err" type="redirect-action">
- <param name="actionName">重定向的Action名</param>
- <param name="namespace">重定向Action所在的名字空间</param>
- </result>
感觉redirect和redirect-action 后者主要来重新定向action - redirect完成两次互交过程
要生成URL :xx.action?name=""&password=""
<param name="name">""</param>
<param name="password">""</param>
来传递参数
- 全局结果:对包内所有的Action都有效的全局结果
- <global-results>
- <result name="resultName">具体视图位置</result>
- </global-results>