Struts2 result的几种type类型说明

<results>标签在Struts2 MVC框架中扮演视图的角色。Action负责执行业务逻辑,下一步就是使用<results>标签显示视图。通常action会配置多个可能的结果字符串以及多个不同的视图来渲染一个处理结果,

Struts提供了许多预定义的结果类型,我们已经看到的是默认的结果类型dispatcher,它用于分发到JSP页面。Struts允许你使用其他标记语言为视图技术呈现结果,较常选用的包括VelocityFreemakerXSLTTiles

  •     
  • dispatcher     

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

 <result name="getlist">WEB-INF/views/holidayApply/list.jsp</result> 
  • redirect    

    重定向到一个jsp或者action或者外部网址 ,被跳转的页面中丢失传递的信息,如request    

<result name="success" type="redirect">/index.jsp</result>  
<result name="success" type="redirect">/login.do</result>  
<result name="success" type="redirect">http://www.baidu.com</result>

//带参数
<result name="success" type="redirect">/login.do?userId=${userId }</result>  
  • chain    

     用来处理Action链,被跳转的action中仍能获取上个页面的值(将请求转发给一个Action,Action能通过getAttribute(“uname”)拿到值 ),如request信息。

<action name="action1" class="org.Action1">  
     <result name="success" type="chain">do</result>  
</action>  
<action name="action2" class="org.Action2">  
     <result name="success">login.jsp</result>  
</action>
  • redirectAction    

    重定向到一个Action ,跳转的页面中丢失传递的信息,如request   

<result name="returnday" type="redirectAction">
    <param name="actionName">holidayApplyAction_getlist.action</param>
</result>
  • redirect-action   

    重定向到一个Action ,跳转的页面中丢失传递的信息,如request 

<result name="success" type="redirect-action">  
     <param name="actionName">login</param>  //重定向action名
     <param name="userId">userId</param> //带的参数
</result>
  • stream    

    向浏览器发送InputSream对象,通常用来处理文件下载,还可用于返回AJAX数据    

<result name="excel" type="stream">
    <param name="contentType">text/html</param>
    <param name="inputName">inputStream</param>
</result>
  • freemaker    

    处理FreeMarker模板    

  • httpheader   

    控制特殊HTTP行为的结果类型    

  • velocity    

    处理Velocity模板     

  • xslt    

    处理XML/XLST模板     

  • plainText    

    显示原始文件内容,例如文件源代码    

  • plaintext    

    显示原始文件内容,例如文件源代码  

<result name="err" type="plaintext">  
    <param name="location">具体的位置</param>  
    <param name="charSet">字符规范(如GBK)</param>  
</result>

  

注:redirectredirect-action区别

一、使用redirect需要后缀名 使用redirect-action不需要后缀名 
二、type="redirect" 的值可以转到其它命名空间下的action,而redirect-action只能转到同一命名空下的 action,因此它可以省略.action的后缀直接写action的名称。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值