﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-硬盘的BLOG-文章分类-Struts2</title><link>http://www.blogjava.net/simen/category/33022.html</link><description>引导分区</description><language>zh-cn</language><lastBuildDate>Wed, 16 Jul 2008 01:12:07 GMT</lastBuildDate><pubDate>Wed, 16 Jul 2008 01:12:07 GMT</pubDate><ttl>60</ttl><item><title>Struts2 addActionError时 使用action标签的注意问题</title><link>http://www.blogjava.net/simen/articles/215103.html</link><dc:creator>我是一块硬盘</dc:creator><author>我是一块硬盘</author><pubDate>Tue, 15 Jul 2008 22:43:00 GMT</pubDate><guid>http://www.blogjava.net/simen/articles/215103.html</guid><wfw:comment>http://www.blogjava.net/simen/comments/215103.html</wfw:comment><comments>http://www.blogjava.net/simen/articles/215103.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/simen/comments/commentRss/215103.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/simen/services/trackbacks/215103.html</trackback:ping><description><![CDATA[
		<font size="2">struts.xml配置文件</font>
		<font size="2">
				<br />
				<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<span style="color: rgb(0, 0, 0);">    </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">action </span>
						<span style="color: rgb(255, 0, 0);">name</span>
						<span style="color: rgb(0, 0, 255);">="*_*_*"</span>
						<span style="color: rgb(255, 0, 0);"> class</span>
						<span style="color: rgb(0, 0, 255);">="{0}Action"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />      </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">result </span>
						<span style="color: rgb(255, 0, 0);">name</span>
						<span style="color: rgb(0, 0, 255);">="input"</span>
						<span style="color: rgb(255, 0, 0);"> type</span>
						<span style="color: rgb(0, 0, 255);">="freemarker"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">/WEB-INF/template/strong/{1}/{1}_{2}_XianShi.ftl</span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">result</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />      </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">result </span>
						<span style="color: rgb(255, 0, 0);">name</span>
						<span style="color: rgb(0, 0, 255);">="success"</span>
						<span style="color: rgb(255, 0, 0);"> type</span>
						<span style="color: rgb(0, 0, 255);">="freemarker"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">/WEB-INF/template/strong/{1}/{0}.ftl</span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">result</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />    </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">action</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
				</div>
				<br />
				<br />登录操作Action 对应Action名为sxt_DengLu_CaoZuo 对应的<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">input </span><span style="color: rgb(0, 0, 0);"></span>result为<span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">WEB</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">INF</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">template</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">strong</span><span style="color: rgb(0, 0, 0);">/sxt</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);"></span>sxt_DengLu_XianShi<span style="color: rgb(0, 0, 0);">.ftl<br /><br /></span>Sxt_DengLu_CaoZuoAction.java<br /></font>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<font size="2">
						<span style="color: rgb(0, 0, 0);">@Component(</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">sxt_DengLu_CaoZuoAction</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">)</span>
						<span style="color: rgb(0, 128, 0);">//</span>
						<span style="color: rgb(0, 128, 0);">使用了Spring 这里的意思是将本Action装配为一个ID为sxt_DengLu_CaoZuoAction的Bean</span>
						<span style="color: rgb(0, 128, 0);">
								<br />
						</span>
						<span style="color: rgb(0, 0, 0);">@Scope(</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">prototype</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">)</span>
						<span style="color: rgb(0, 128, 0);">//</span>
						<span style="color: rgb(0, 128, 0);">作用域为prototype 即每次都使用新的对象</span>
						<span style="color: rgb(0, 128, 0);">
								<br />
						</span>
						<span style="color: rgb(0, 0, 255);">public</span>
						<span style="color: rgb(0, 0, 0);"> </span>
						<span style="color: rgb(0, 0, 255);">class</span>
						<span style="color: rgb(0, 0, 0);"> Sxt_DengLu_CaoZuoAction </span>
						<span style="color: rgb(0, 0, 255);">extends</span>
						<span style="color: rgb(0, 0, 0);"> ActionSupport </span>
						<span style="color: rgb(0, 0, 255);">implements</span>
						<span style="color: rgb(0, 0, 0);">  ModelDriven</span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">MYh</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);"> {</span>
				</font>
		</div>
		<font size="2">
				<br />
				<br />导航列表Action 对应Action名为sxt_DaoHang_XianShi 对应的<span style="color: rgb(0, 0, 0);">success </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span>result为<span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">WEB</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">INF</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">template</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">strong</span><span style="color: rgb(0, 0, 0);">/sxt</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);"></span>sxt_DaoHang_XianShi<span style="color: rgb(0, 0, 0);">.ftl<br /><br /></span>Sxt_DaoHang_XianShiAction.java<br /></font>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<font size="2">
						<span style="color: rgb(0, 0, 0);">@Component(</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">sxt_DaoHang_XianShiAction</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">)</span>
						<span style="color: rgb(0, 128, 0);">//</span>
						<span style="color: rgb(0, 128, 0);"> 同上</span>
						<span style="color: rgb(0, 128, 0);">
								<br />
						</span>
						<span style="color: rgb(0, 0, 0);">@Scope(</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">prototype</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">)</span>
						<span style="color: rgb(0, 128, 0);">//</span>
						<span style="color: rgb(0, 128, 0);">同上</span>
						<span style="color: rgb(0, 128, 0);">
								<br />
						</span>
						<span style="color: rgb(0, 0, 255);">public</span>
						<span style="color: rgb(0, 0, 0);"> </span>
						<span style="color: rgb(0, 0, 255);">class</span>
						<span style="color: rgb(0, 0, 0);"> Sxt_DaoHang_XianShiAction </span>
						<span style="color: rgb(0, 0, 255);">extends</span>
						<span style="color: rgb(0, 0, 0);"> ActionSupport  </span>
						<span style="color: rgb(0, 0, 255);">implements</span>
						<span style="color: rgb(0, 0, 0);"> Preparable{<br /></span>
				</font>
		</div>
		<font size="2">
				<br />
				<br />
				<span style="color: rgb(0, 0, 0);">
				</span>
				<span style="color: rgb(0, 0, 0);">
				</span>sxt_DengLu_XianShi<span style="color: rgb(0, 0, 0);">.ftl</span><span style="color: rgb(0, 0, 0);"><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 使用action标签将导航列表导入到本页面</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">@s.action name</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sxt_DaoHang_XianShi</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> namespace</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/ht</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> executeResult</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);"> ignoreContextParams</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">@s.form action</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sxt_DengLu_CaoZuo</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> id</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">form_login</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> theme</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">simple</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">table align</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">CENTER</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> id</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">table_login</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">td_label</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">登录名</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">td_input</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;&lt;</span><span style="color: rgb(0, 0, 0);">@s.textfield label</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${action.getText('TYH_YHDLM')}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> id</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">yhDlm</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> name</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">yhDlm</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">/&gt;&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">td_label</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">密码</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">td_input</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;&lt;</span><span style="color: rgb(0, 0, 0);">@s.password label</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${action.getText('TYH_YHMM')}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> id</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">yhMm</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> name</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">yhMm</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">/&gt;&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">td_label</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;&amp;</span><span style="color: rgb(0, 0, 0);">nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">td_input</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;&lt;</span><span style="color: rgb(0, 0, 0);">p id</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">p_submit</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">@s.submit value</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${action.getText('PAGE_DENG_LU')}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">input type</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">button</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> value</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${action.getText('PAGE_TUI_CHU')}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">p</span><span style="color: rgb(0, 0, 0);">&gt;&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">table</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">@s.form</span><span style="color: rgb(0, 0, 0);">&gt;</span></div><br /><br /></span>sxt_DaoHang_XianShi<span style="color: rgb(0, 0, 0);">.ftl<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">ul</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">#list listDaoHangLieBiao as nav</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">li</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    ${nav}<br />  </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">li</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">#list</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">ul</span><span style="color: rgb(0, 0, 0);">&gt;</span></div><br /><br /></span>Sxt_DengLu_CaoZuoAction.java 执行execute<br /></font>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<font size="2">
						<span style="color: rgb(0, 0, 0);">  @Override<br />  </span>
						<span style="color: rgb(0, 0, 255);">public</span>
						<span style="color: rgb(0, 0, 0);"> String execute() </span>
						<span style="color: rgb(0, 0, 255);">throws</span>
						<span style="color: rgb(0, 0, 0);"> Exception {<br />    </span>
						<span style="color: rgb(0, 0, 255);">this</span>
						<span style="color: rgb(0, 0, 0);">.addActionError(</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">系统错误</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">);<br />    </span>
						<span style="color: rgb(0, 0, 255);">return</span>
						<span style="color: rgb(0, 0, 0);"> INPUT;<br />  }</span>
				</font>
		</div>
		<font size="2">
				<br />
				<br />Sxt_DaoHang_XianShiAction.java 执行execute<br /></font>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<font size="2">
						<span style="color: rgb(0, 0, 0);">  @Override<br />  </span>
						<span style="color: rgb(0, 0, 255);">public</span>
						<span style="color: rgb(0, 0, 0);"> String execute() </span>
						<span style="color: rgb(0, 0, 255);">throws</span>
						<span style="color: rgb(0, 0, 0);"> Exception {<br />    ActionContext ctx </span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);"> ActionContext.getContext();<br />    ctx.put(</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">listDaoHangLieBiao</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">, </span>
						<span style="color: rgb(0, 0, 255);">new</span>
						<span style="color: rgb(0, 0, 0);"> ArrayList());<br />    </span>
						<span style="color: rgb(0, 0, 255);">return</span>
						<span style="color: rgb(0, 0, 0);"> SUCCESS;<br />  }</span>
				</font>
		</div>
		<font size="2">
				<br />这个时候执行代码 freemarker会提示“&lt;pre&gt;Expression listDaoHangLieBiao is undefined&lt;/pre&gt;”为什么会这样了？<br />仔细查找了相关资料 发现apache的文档 http://struts.apache.org/2.x/docs/how-do-we-repopulate-controls-when-validation-fails.html中写道<br /></font>
		<p>
				<font size="2">When validation fails, we typically forward back to the same server
page, so that the errors can be presented, and so that the client can
fix the problem and resubmit the form. Of course, aside from the
errors, we may also need to present rich controls, like drop down
lists. </font>
		</p>
		<p>
				<font size="2">If we try to populate rich controls in an <tt>Action</tt> method, like <tt>input</tt> or <tt>execute</tt>,
and validation fails, the method will not be invoked, and the controls
are not populated. Two alternative ways to populate controls are the <tt>Preparable</tt> interface and the <tt>action</tt> tag. <br /></font>
		</p>
		<p>
				<font size="2">大致的意思是但出现validation错误的时候会影响到Action的正常执行，这个时候应该实现<tt>Preparable</tt>接口中的prepare()方法，这个方法中的操作不会因为validation错误而不执行。</font>
		</p>
		<p>
				<font size="2">联想到上面的错，会不会也是因为addActionError而导致不能正常使用action标签了。为此在Sxt_DaoHang_XianShiAction中实现Preparable接口并在prepare()方法中put <span style="color: rgb(0, 0, 0);">listDaoHangLieBiao。修改代码如下</span></font>
		</p>
		<p>
				<font size="2">Sxt_DaoHang_XianShiAction.java</font>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<font size="2">
						<span style="color: rgb(0, 0, 0);">@Component(</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">sxt_DaoHang_XianShiAction</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">)<br />@Scope(</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">prototype</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">)<br /></span>
						<span style="color: rgb(0, 0, 255);">public</span>
						<span style="color: rgb(0, 0, 0);"> </span>
						<span style="color: rgb(0, 0, 255);">class</span>
						<span style="color: rgb(0, 0, 0);"> Sxt_DaoHang_XianShiAction </span>
						<span style="color: rgb(0, 0, 255);">extends</span>
						<span style="color: rgb(0, 0, 0);"> ActionSupport  </span>
						<span style="color: rgb(0, 0, 255);">implements</span>
						<span style="color: rgb(0, 0, 0);"> Preparable{<br /><br />  @Override<br />  </span>
						<span style="color: rgb(0, 0, 255);">public</span>
						<span style="color: rgb(0, 0, 0);"> String execute() </span>
						<span style="color: rgb(0, 0, 255);">throws</span>
						<span style="color: rgb(0, 0, 0);"> Exception {<br />    </span>
						<span style="color: rgb(0, 0, 255);">return</span>
						<span style="color: rgb(0, 0, 0);"> SUCCESS;<br />  }<br /><br />  </span>
						<span style="color: rgb(0, 0, 255);">public</span>
						<span style="color: rgb(0, 0, 0);"> </span>
						<span style="color: rgb(0, 0, 255);">void</span>
						<span style="color: rgb(0, 0, 0);"> prepare() </span>
						<span style="color: rgb(0, 0, 255);">throws</span>
						<span style="color: rgb(0, 0, 0);"> Exception {<br />    ActionContext ctx </span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);"> ActionContext.getContext();<br />    ctx.put(</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">listDaoHangLieBiao</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">, Constants.DAO_HANG_LIE_BIAO);<br />  }<br />}<br /></span>
				</font>
		</div>
		<font size="2">
				<br />再执行==成功。</font>
		<p>
				<font size="2">总结 Struts2目前的资料相对Struts1来说是非常少的，尤其是研究的很深的资料，看来现在想学好Struts2还必须从Apache的原始资料中寻找。</font>
		</p>
		<p>
				<font size="2">另外上面使用action标签的时候是这样写的</font>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<font size="2">
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">@s.action name</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">sxt_DaoHang_XianShi</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);"> namespace</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">/ht</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);"> executeResult</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 255);">true</span>
						<span style="color: rgb(0, 0, 0);"> ignoreContextParams</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 255);">true</span>
						<span style="color: rgb(0, 0, 0);"> </span>
						<span style="color: rgb(0, 0, 0);">/&gt;</span>
				</font>
		</div>
		<font size="2">
				<br />注意和Struts2的标签写法略有不同，因为这里使用了Freemarker做模板，所以使用的freemarker的写法，特别的是<span style="color: rgb(0, 0, 0);">executeResult</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);"> ignoreContextParams</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">而按照Struts2的标签应该是</span><span style="color: rgb(0, 0, 0);">executeResult</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">"true"</span><span style="color: rgb(0, 0, 0);"> ignoreContextParams</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">"true"</span></font>
		<p>
				<font size="2">
						<span style="color: rgb(0, 0, 255);">
						</span>
						<span style="color: rgb(0, 0, 0);">
						</span>哈哈 小小两个引号 害我折腾N个小时<br /><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span></font>
		</p>
<img src ="http://www.blogjava.net/simen/aggbug/215103.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/simen/" target="_blank">我是一块硬盘</a> 2008-07-16 06:43 <a href="http://www.blogjava.net/simen/articles/215103.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>