<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>UKoom &#187; Struts</title>
	<atom:link href="http://www.ukoom.com/tag/struts/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ukoom.com</link>
	<description>Documentum, SharePoint, Alfresco, ECM...</description>
	<lastBuildDate>Thu, 13 May 2010 00:21:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Struts2 Result Type</title>
		<link>http://www.ukoom.com/struts2-result-type.htm</link>
		<comments>http://www.ukoom.com/struts2-result-type.htm#comments</comments>
		<pubDate>Wed, 20 Jan 2010 13:58:09 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Web MVC]]></category>
		<category><![CDATA[Struts]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=1020</guid>
		<description><![CDATA[Result Types are [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Result Types</strong> are classes that determine what happens after an Action executes and a Result is returned. Developers are free to create their own Result Types according to the needs of their application or environment. In WebWork 2 for example, Servlet and Velocity Result Types have been created to handle rendering views in web applications.</p>
<p><ins>Note:</ins> All built in webwork result types implement the <tt>com.opensymphony.xwork.Result</tt> interface, which represents a generic interface for all action execution results, whether that be displaying a webpage, generating an email, sending a JMS message, etc.</p>
<p>Result types define classes and map them to names to be referred in the action configuration results. This serves as a shorthand name-value pair for these classes.</p>
<div id="blog_text">
<div>一个提交到服务器的处理通常可以分为两个阶段，第一个阶段查询服务器状态（查询或者更新数据库），第二个阶段选择一个合适的结果页面其返回给用户（这里要讲的Result的内容）。</div>
<div>Struts2提供了对不同种类返回结果的支持，常见的有JSP，FreeMarker，Velocity等。</div>
<div>Struts2支持的不同类型的返回结果为：</div>
<table style="border: medium none ; border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border: 1pt solid black; padding: 0cm 5.4pt; background: #bfbfbf none repeat scroll 0% 0%; width: 113.3pt;" width="151" valign="top">
<div><strong>名字</strong></div>
</td>
<td style="padding: 0cm 5.4pt; background: #bfbfbf none repeat scroll 0% 0%; width: 274.2pt;" width="366" valign="top">
<div><strong>说明</strong></div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>Chain Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>用来处理Action链</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>Dispatcher Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>用来转向页面，通常处理JSP</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>FreeMarker Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>处理FreeMarker模板</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>HttpHeader Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>用来控制特殊的Http行为</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>Redirect Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>重定向到一个URL</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>Redirect Action Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>重定向到一个Action</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>Stream Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>向浏览器发送InputSream对象，通常用来处理文件下载</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>Velocity Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>处理Velocity模板</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>XLS Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>处理XML/XLST模板</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>PlainText Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>显示原始文件内容，例如文件源代码</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt;" width="151" valign="top">
<div>S2PLUGINS:Tiles Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt;" width="366" valign="top">
<div>结合Tile使用</div>
</td>
</tr>
</tbody>
</table>
<div>另外第三方的Result类型还包括JasperReports Plugin，专门用来处理JasperReport类型的报表输出。</div>
<div>在struts-default.xml文件中已经有了对于所有类型Result的定义：</div>
<div>&lt;result-types&gt;</div>
<div><span>&lt;result-type name=&#8221;chain&#8221;</span></div>
<div><span>class=&#8221;com.opensymphony.xwork2.ActionChainResult&#8221;/&gt;</span></div>
<div><strong><span>&lt;result-type name=&#8221;dispatcher&#8221;</span></strong></div>
<div><strong><span>class=&#8221;org.apache.struts2.dispatcher.ServletDispatcherResult&#8221;</span></strong></div>
<div><strong><span>default=&#8221;true&#8221;/&gt;</span></strong></div>
<div><span>&lt;result-type name=&#8221;freemarker&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.views.freemarker.FreemarkerResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;httpheader&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.HttpHeaderResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;redirect&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.ServletRedirectResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;redirectAction&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.ServletActionRedirectResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;stream&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.StreamResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;velocity&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.VelocityResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;xslt&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.views.xslt.XSLTResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;plainText&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.PlainTextResult&#8221; /&gt;</span></div>
<div><span>&lt;!&#8211; Deprecated name form scheduled for removal in Struts 2.1.0.</span></div>
<div><span>The camelCase versions are preferred. See ww-1707 &#8211;&gt;</span></div>
<div><span>&lt;result-type name=&#8221;redirect-action&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.ServletActionRedirectResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;plaintext&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.PlainTextResult&#8221; /&gt;</span></div>
<div>&lt;/result-types&gt;</div>
<div>
<p>从上述代码中可以看出在不指定Result类型的时候使用dispatcher类型。</p></div>
<div>定义一个Result值，</div>
<div>&lt;result name=&#8221;success&#8221; type=&#8221;dispatcher&#8221;&gt;</div>
<div><span>&lt;param name=&#8221;location&#8221;&gt;/ThankYou.jsp&lt;/param&gt;</span></div>
<div>&lt;/result&gt;</div>
<div>由于type默认值是dispatcher，所以这里不需要定义，另外name的默认值为success所以这里也不需要定义。</div>
<div>上述代码可以简写为：</div>
<div>&lt;result&gt;</div>
<div><span>&lt;param name=&#8221;location&#8221;&gt;/ThankYou.jsp&lt;/param&gt;</span></div>
<div>
<p>&lt;/result&gt;</p></div>
<div>另外location参数也可以直接卸载result标签内部，所以上述代码的最简单的写法为：</div>
<div>&lt;result&gt;/ThankYou.jsp&lt;/result&gt;</div>
<div>我们也可以定义多个不同的Result</div>
<div>&lt;action name=&#8221;Hello&#8221;&gt;</div>
<div>&lt;result&gt;/hello/Result.jsp&lt;/result&gt;</div>
<div>&lt;result name=&#8221;error&#8221;&gt;/hello/Error.jsp&lt;/result&gt;</div>
<div>&lt;result name=&#8221;input&#8221;&gt;/hello/Input.jsp&lt;/result&gt;</div>
<div>&lt;/action&gt;</div>
<div>上述代码的含义为，名字为Hello的Action有三个返回结果，并且都是dispatcher类型（默认类型），这三个返回值的名字分别为 success（默认值），error，input，对应的页面的路径分别为/hello/Result.jsp，/hello/Error.jsp， /hello/Input.jsp。</div>
<div>有些时候我们需要一个定义在全局的Result，这个时候我们可以在package内部定义全局的Result，例如：</div>
<div>&lt;global-results&gt;</div>
<div>&lt;result name=&#8221;error&#8221;&gt;/Error.jsp&lt;/result&gt;</div>
<div>&lt;result name=&#8221;invalid.token&#8221;&gt;/Error.jsp&lt;/result&gt;</div>
<div>&lt;result name=&#8221;login&#8221; type=&#8221;redirect-action&#8221;&gt;Logon!input&lt;/result&gt;</div>
<div>
<p>&lt;/global-results&gt;</p></div>
<div><strong>动态返回结果</strong></div>
<div>有些时候，只有当Action执行完璧的时候我们才知道要返回哪个结果，这个时候我们可以在Action内部定义一个属性，这个属性用来存储Action执行完璧之后的Result值，例如：</div>
<div>private String nextAction;</div>
<div>public String getNextAction() {</div>
<div><span>return nextAction;</span></div>
<div>}</div>
<div>在strutx.xml配置文件中，我们可以使用${nextAction}来引用到Action中的属性，通过${nextAction}表示的内容来动态的返回结果，例如：</div>
<div>&lt;action name=&#8221;fragment&#8221;&gt;</div>
<div>&lt;result name=&#8221;next&#8221; type=&#8221;redirect-action&#8221;&gt;${nextAction}&lt;/result&gt;</div>
<div>&lt;/action&gt;</div>
<div>上述Action的execute方法返回next的时候，还需要根据nextAction的属性来判断具体定位到哪个Action。</div>
<div>如果想转发到另外个action可以设置type=chain 同时结果不加shtml</div>
</div>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.ukoom.com/freemarker-result.htm" title="FreeMarker Result">FreeMarker Result</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/struts2-result-type.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FreeMarker Result</title>
		<link>http://www.ukoom.com/freemarker-result.htm</link>
		<comments>http://www.ukoom.com/freemarker-result.htm#comments</comments>
		<pubDate>Wed, 20 Jan 2010 13:55:04 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Web MVC]]></category>
		<category><![CDATA[Struts]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=1018</guid>
		<description><![CDATA[Renders a view [...]]]></description>
			<content:encoded><![CDATA[<p>Renders a view using the Freemarker template engine.</p>
<p>The FreemarkarManager class configures the template loaders so that the template location can be either</p>
<ul>
<li>relative to the web root folder. eg <code>/WEB-INF/views/home.ftl</code></li>
<li>a classpath resuorce. eg <code>/com/company/web/views/home.ftl</code></li>
</ul>
<p>Parameters</p>
<p>* location (default) &#8211; the location of the template to process.</p>
<p>* parse &#8211; true by default. If set to false, the location param will not be parsed for Ognl expressions.</p>
<p>* contentType &#8211; defaults to &#8220;text/html&#8221; unless specified.</p>
<p>* writeIfCompleted &#8211; false by default, write to stream only if there isn&#8217;t any error processing the template. Setting template_exception_handler=rethrow in freemarker.properties will have the same effect.</p>
<p>Examples</p>
<pre><span>&lt;result name=<span>"success"</span> type=<span>"freemarker"</span>&gt;</span>foo.ftl<span>&lt;/result&gt;

Of course, we can also omit the 'type' setting by setting the result type
of struts. Please refer to another article of this site - Struts result type.

</span></pre>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 337px; width: 1px; height: 1px;">
<div id="blog_text" class="cnt">
<div>一个提交到服务器的处理通常可以分为两个阶段，第一个阶段查询服务器状态（查询或者更新数据库），第二个阶段选择一个合适的结果页面其返回给用户（这里要讲的Result的内容）。</div>
<div></div>
<div>Struts2提供了对不同种类返回结果的支持，常见的有JSP，FreeMarker，Velocity等。</div>
<div>Struts2支持的不同类型的返回结果为：</div>
<table style="border: medium none ; border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border: 1pt solid black; padding: 0cm 5.4pt; background: #bfbfbf none repeat scroll 0% 0%; width: 113.3pt;" width="151" valign="top">
<div><strong>名字</strong></div>
</td>
<td style="padding: 0cm 5.4pt; background: #bfbfbf none repeat scroll 0% 0%; width: 274.2pt; border: 1pt 1pt 1pt medium solid solid solid none -moz-use-text-color;" width="366" valign="top">
<div><strong>说明</strong></div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>Chain Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>用来处理Action链</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>Dispatcher Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>用来转向页面，通常处理JSP</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>FreeMarker Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>处理FreeMarker模板</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>HttpHeader Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>用来控制特殊的Http行为</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>Redirect Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>重定向到一个URL</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>Redirect Action Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>重定向到一个Action</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>Stream Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>向浏览器发送InputSream对象，通常用来处理文件下载</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>Velocity Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>处理Velocity模板</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>XLS Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>处理XML/XLST模板</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>PlainText Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>显示原始文件内容，例如文件源代码</div>
</td>
</tr>
<tr>
<td style="padding: 0cm 5.4pt; width: 113.3pt; border: medium 1pt 1pt none solid solid -moz-use-text-color;" width="151" valign="top">
<div>S2PLUGINS:Tiles Result</div>
</td>
<td style="padding: 0cm 5.4pt; width: 274.2pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color;" width="366" valign="top">
<div>结合Tile使用</div>
</td>
</tr>
</tbody>
</table>
<div>另外第三方的Result类型还包括JasperReports Plugin，专门用来处理JasperReport类型的报表输出。</div>
<div></div>
<div>在struts-default.xml文件中已经有了对于所有类型Result的定义：</div>
<div>&lt;result-types&gt;</div>
<div><span>&lt;result-type name=&#8221;chain&#8221;</span></div>
<div><span>class=&#8221;com.opensymphony.xwork2.ActionChainResult&#8221;/&gt;</span></div>
<div><strong><span>&lt;result-type name=&#8221;dispatcher&#8221;</span></strong></div>
<div><strong><span>class=&#8221;org.apache.struts2.dispatcher.ServletDispatcherResult&#8221;</span></strong></div>
<div><strong><span>default=&#8221;true&#8221;/&gt;</span></strong></div>
<div><span>&lt;result-type name=&#8221;freemarker&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.views.freemarker.FreemarkerResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;httpheader&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.HttpHeaderResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;redirect&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.ServletRedirectResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;redirectAction&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.ServletActionRedirectResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;stream&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.StreamResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;velocity&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.VelocityResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;xslt&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.views.xslt.XSLTResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;plainText&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.PlainTextResult&#8221; /&gt;</span></div>
<div><span>&lt;!&#8211; Deprecated name form scheduled for removal in Struts 2.1.0.</span></div>
<div><span>The camelCase versions are preferred. See ww-1707 &#8211;&gt;</span></div>
<div><span>&lt;result-type name=&#8221;redirect-action&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.ServletActionRedirectResult&#8221;/&gt;</span></div>
<div><span>&lt;result-type name=&#8221;plaintext&#8221;</span></div>
<div><span>class=&#8221;org.apache.struts2.dispatcher.PlainTextResult&#8221; /&gt;</span></div>
<div>&lt;/result-types&gt;</div>
<div></div>
<div>
<p>从上述代码中可以看出在不指定Result类型的时候使用dispatcher类型。</p></div>
<div></div>
<div>定义一个Result值，</div>
<div>&lt;result name=&#8221;success&#8221; type=&#8221;dispatcher&#8221;&gt;</div>
<div><span>&lt;param name=&#8221;location&#8221;&gt;/ThankYou.jsp&lt;/param&gt;</span></div>
<div>&lt;/result&gt;</div>
<div>由于type默认值是dispatcher，所以这里不需要定义，另外name的默认值为success所以这里也不需要定义。</div>
<div>上述代码可以简写为：</div>
<div>&lt;result&gt;</div>
<div><span>&lt;param name=&#8221;location&#8221;&gt;/ThankYou.jsp&lt;/param&gt;</span></div>
<div>
<p>&lt;/result&gt;</p></div>
<div>另外location参数也可以直接卸载result标签内部，所以上述代码的最简单的写法为：</div>
<div>&lt;result&gt;/ThankYou.jsp&lt;/result&gt;</div>
<div></div>
<div>我们也可以定义多个不同的Result</div>
<div>&lt;action name=&#8221;Hello&#8221;&gt;</div>
<div>&lt;result&gt;/hello/Result.jsp&lt;/result&gt;</div>
<div>&lt;result name=&#8221;error&#8221;&gt;/hello/Error.jsp&lt;/result&gt;</div>
<div>&lt;result name=&#8221;input&#8221;&gt;/hello/Input.jsp&lt;/result&gt;</div>
<div>&lt;/action&gt;</div>
<div>上述代码的含义为，名字为Hello的Action有三个返回结果，并且都是dispatcher类型（默认类型），这三个返回值的名字分别为 success（默认值），error，input，对应的页面的路径分别为/hello/Result.jsp，/hello/Error.jsp， /hello/Input.jsp。</div>
<div></div>
<div>有些时候我们需要一个定义在全局的Result，这个时候我们可以在package内部定义全局的Result，例如：</div>
<div>&lt;global-results&gt;</div>
<div>&lt;result name=&#8221;error&#8221;&gt;/Error.jsp&lt;/result&gt;</div>
<div>&lt;result name=&#8221;invalid.token&#8221;&gt;/Error.jsp&lt;/result&gt;</div>
<div>&lt;result name=&#8221;login&#8221; type=&#8221;redirect-action&#8221;&gt;Logon!input&lt;/result&gt;</div>
<div>
<p>&lt;/global-results&gt;</p></div>
<div></div>
<div><strong>动态返回结果</strong></div>
<div>有些时候，只有当Action执行完璧的时候我们才知道要返回哪个结果，这个时候我们可以在Action内部定义一个属性，这个属性用来存储Action执行完璧之后的Result值，例如：</div>
<div>private String nextAction;</div>
<div></div>
<div>public String getNextAction() {</div>
<div><span>return nextAction;</span></div>
<div>}</div>
<div></div>
<div>在strutx.xml配置文件中，我们可以使用${nextAction}来引用到Action中的属性，通过${nextAction}表示的内容来动态的返回结果，例如：</div>
<div>&lt;action name=&#8221;fragment&#8221; class=&#8221;FragmentAction&#8221;&gt;</div>
<div>&lt;result name=&#8221;next&#8221; type=&#8221;redirect-action&#8221;&gt;${nextAction}&lt;/result&gt;</div>
<div>&lt;/action&gt;</div>
<div></div>
<div>上述Action的execute方法返回next的时候，还需要根据nextAction的属性来判断具体定位到哪个Action。</div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div>如果想转发到另外个action可以设置type=chain 同时结果不加shtml</div>
</div>
</div>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.ukoom.com/struts2-result-type.htm" title="Struts2 Result Type">Struts2 Result Type</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/freemarker-result.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
