Struts2 Result Types

来源:互联网 发布:php异步请求 编辑:程序博客网 时间:2024/06/04 18:55
  • Struts2的action基类中提供了基本的result name的定义:
String SUCCESS = "success";String NONE    = "none";String ERROR   = "error";String INPUT   = "input";String LOGIN   = "login";
  • 一个标准的result的设置
<result name="success" type="dispatcher">    <param name="location">/ThankYou.jsp</param></result>
  • 使用default设置的result配置
<result>    <param name="location">/ThankYou.jsp</param></result>
name的缺省值是"success", type的缺省值是"dispatcher"
  • 简化的result配置

<result>/ThankYou.jsp</result>
  • 多result配置
<action name="Hello">    <result>/hello/Result.jsp</result>    <result name="error">/hello/Error.jsp</result>    <result name="input">/hello/Input.jsp</result>    <result name="*">/hello/Other.jsp</result></action>

'*'不是通配符,当返回的result定义在配置中找不到时,则使用该配置

  • 当action的方法不需要提供返回的页面时,使用 ActionSupport.NONE (ornull) 。使用ajax是一个典型的例子。这是需要程序会直接向HttpServletResponse OutputStream中写数据。
  • 一个redirect的例子
<package name="passingRequestParameters" extends="struts-default" namespace="/passingRequestParameters">   <-- Pass parameters (reportType, width and height) -->   <!--   The redirect-action url generated will be :   /genReport/generateReport.jsp?reportType=pie&width=100&height=100#summary   -->   <action name="gatherReportInfo" class="...">      <result name="showReportResult" type="redirect">         <param name="location">generateReport.jsp</param>         <param name="namespace">/genReport</param>         <param name="reportType">pie</param>         <param name="width">100</param>         <param name="height">100</param>         <param name="anchor">summary</param>      </result>   </action></package>
  • chain如何用???
  • xwork 支持的result type类型

<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>
在struts-default.xml中可以查阅到以上的result type配置。 从中dispatcher是一个缺省的result type

原创粉丝点击