struts2的result标签

result name="success" type="dispatcher">/hello.jsp</result>


 
如果没有指定name属性:则默认是success;如果没有指定type,则默认就是dispatcher。


------------


    结果类型


------------

chain:          Action链式处理的结果类型,也就是将结果转发到这个action中。
chart:          整合JFreeChart的结果类型
dispatcher:     请求转发,用于整合JSP的结果类型
freemarker:     用于整合freemarker结果类型。
httpheader:     用于控制特殊的HTTP行为的结果类型。
jasper:         用于JasperReports整合的结果类型
jsf:            用于整合JSF后的结果类型
redirect:       请求重定向。值为一个请求URL
redirect-action:请求重定向到action。值为定义的action的name。
stream:         用于向浏览器返回一个Inputstream(用于文件下载)
tiles:          用于整合Tiles后的结果类型。
velocity:       用于整合Velocity的结果类型。
xslt:           用于整合XML/XSLT的结果类型。
plaintext:      用于显示某个页面的源代码。
 

 

例:

<result type="redirect">
 <param name="location">/result.jsp</param>
 <param name="charset">UTF-8</param>    设置字符集编码
</result>
 
<result type="redirect-action">
 <param name="namespace">/user</param>  指定action的命名空间
 <param name="actionName">login</param> 指定action的名字
</result>

 

---------------------------------


       在请求结果中使用ONGL表达式


---------------------------------

parse:该参数指定是否允许在实际视图名称中使用ONGL表达式,默认为true。如果设置为false则不允许使用。
 
例子:
<result type="redirect">

     login.action?username=${user.username}

</result>
 
对于上面的表达式语法,要求action中必须包含user属性,并且user属性必须包含username属性,否则值为null。

 


--------------------------------------


      redirect和redirect-action的区别


--------------------------------------

redirect-action的actionName是重定向到action名
redirect的actionName是action执行后的跳转路径


-1-
login为action的名字而非路径
<result name="aaa" type="redirect-action">login</result>

 

-2-
LoginAction类中必须有 name 和 password 这两个属性以及getter方法
其中的值是一个请求的相对路径
<result name="bbb" type="redirect">
 login.action?name=${name}&password=${password}
</result>

 

-3-


LoginAction类中必须有 username 和 password 这两个属性以及getter方法
<result name="ccc" type="redirect-action">
 <param name="actionName">login</param>      指定要重定向到的action的名字
 <param name="username">${username}</param>  指定提交的参数
 <param name="password">${password}</param>
</result>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值