Result类型
Webwork提供了一些com.opensymphony.xwork.Result接口的实现来使你的action可以容易的用户交互.这些Result类型包括:
- Chain Result - 用于 Action Chaining
- Dispatcher Result - 用于 JSP 整合
- FreeMarker Result - 用于 FreeMarker 整合
- HttpHeader Result - 用于控制特殊的HTTP行为
- JasperReports Result - 用于 JasperReports 整合
- Redirect Result - 用于直接跳转到例外的URL
- Redirect Action Result - 用于直接跳转到另外的action
- Stream Result - 用于向浏览器返回一个InputStream (一般用于文件下载)
- Velocity Result - 用于 Velocity 整合
- XSL Result - 用于 XML/XSLT 整合
- PlainText Result - 用于显示某个页面的原始的文本 (例如 jsp, html 等)
Result定义在xwork xml配置文件(xwork.xml)中的action标签里。如果location参数是result标签的唯一的参数,你可以这样简化:
<action name="bar" class="myPackage.barAction">
<result name="success" type="dispatcher">
<param name="location">foo.jsp</param>
</result>
</action>
或者< action name ="bar" class ="myPackage.barAction" >
< result name ="success" type ="dispatcher" >foo.jsp </ result >
</action >
如果你扩展了webwork-default.xml, 那么默认的返回类型是"dispatcher". 同样,如果你没有指定result的名字,默认将是"success". 就是说你可以如下简化:
< action name ="bar" class ="myPackage.barAction" >
<result>foo.jsp</result >
</ action >
注意 : Parse属性允许的location参数作为表达式.例如你可以这样用:
Struts2中从一个Action跳转到另一个action,必须将type="redirect"
<result name ="success" type ="redirect" >/displayCart.action?userId=${userId}
</ result >