struts2默认的Result

struts-default.xml中默认result定义,如下:

<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接口源码,如下:

package com.opensymphony.xwork2;

import java.io.Serializable;

public interface Result extends Serializable {

    publicvoid execute(ActionInvocation invocation) throws Exception;

}

 

返回类型说明(不管是什么类型,最终就是调用HttpResponse使用HTTP协议输出一堆字符串;)

chain

服务器端跳转,action跳action;

dispatcher

服务器端跳转,action跳jsp;默认是dispatcher返回;

freemarker

服务器端跳转,action跳.ftl模板;

httpheader

客户端跳转,action返回http协议的特定属性到客户端;

redirect

客户端重定向,action跳客户端再跳服务器的url;浏览器重定向不能重定向至WEB-INF目录,WEB-INF只能是服务器端转发JSP给客户端浏览器;

redirectAction

客户端重定向,action跳客户端再跳服务器的action;

stream

客户端跳转,action返回一个数据流到客户端浏览器;

velocity

服务器端跳转,action跳.vm模板;

xslt

服务器端跳转,action跳xml/xslt模板;

plainText

直接返回原文件内容,例如文件源码;默认是使用系统默认编码来读取对应的文件的,可以在XML中通过param来配置location、charSet;具体可以去看实现类的帮助文档或者源码;

 

注意:

1)struts.xml中,一般都要继承extends="struts-default"包,这样才能使用默认包中的定义,子类可以访问父类的定义;

2)struts.xml中,当一个包声明为abstract="true"时,这个包只能用来做声明,不能定义Action;

3)Action与Result都可以在XML配置中,加入param参数标签,为Action注入参数值;在重定向Action的时候,如果不在一个包中,可以通过设置param来指定具体的Action路径来访问;

4)在.properties和.xml配置文件中,可以通过OGNL表达式(${XXX})来访问ValueStack里面的值;

5)可以在struts.xml中定义全局Result跟exception跳转

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值