﻿<?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-Mr.Qiu’BlogJava</title><link>http://www.blogjava.net/Mr-Qiu/</link><description>额滴javaBlog</description><language>zh-cn</language><lastBuildDate>Fri, 17 Apr 2026 22:38:17 GMT</lastBuildDate><pubDate>Fri, 17 Apr 2026 22:38:17 GMT</pubDate><ttl>60</ttl><item><title>Struts的静态数据验证方法 </title><link>http://www.blogjava.net/Mr-Qiu/archive/2008/04/03/190583.html</link><dc:creator>Mr.Qiu</dc:creator><author>Mr.Qiu</author><pubDate>Thu, 03 Apr 2008 03:55:00 GMT</pubDate><guid>http://www.blogjava.net/Mr-Qiu/archive/2008/04/03/190583.html</guid><wfw:comment>http://www.blogjava.net/Mr-Qiu/comments/190583.html</wfw:comment><comments>http://www.blogjava.net/Mr-Qiu/archive/2008/04/03/190583.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Mr-Qiu/comments/commentRss/190583.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Mr-Qiu/services/trackbacks/190583.html</trackback:ping><description><![CDATA[<p>&nbsp;<span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">&nbsp;&nbsp;利用</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Struts</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的静态数据验证方法可以对用户在表单上输入的数据进行验证，包括数据类型是否正确、是否可空等。方法如下：</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp; 1</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">、在</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">struts-config.xml</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">文件中加入</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;message-resources parameter="ApplicationResources" /&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;plug-in className="org.apache.struts.validator.ValidatorPlugIn"&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&lt;set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" /&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/plug-in&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">其中</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">parameter="ApplicationResources"</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">意味着在</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">java</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">源代码根部</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">,</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">如</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">src/</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">下有一属性文件</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">ApplicationResources.properties</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">，但为了能显示中文件信息</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">在</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">src/</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">下还应有文件</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">ApplicationResources_zh_CN.properties</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">，</font></span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"> </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">两文件最后打包到</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">WEB-INF/classes</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">下。</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp; 2</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">、利用开发工具在</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">WEB-INF/</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">下导入</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">validator-rules.xml</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">及</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">validation.xml</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">文件。这是有关验证规则及验证内容的配置文件。</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp; 3</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">、为表单属性加入中文说明，如有个</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">formBean</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">，名为</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">form1</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">，有三个属性，</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">name</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">、</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">height</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">、</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">born</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">，分别是姓名、身高、出身日期</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">在</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">ApplicationResources.properties</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">文件中加入属性的解释说明：</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errors.integer={0} </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">必须为整型值</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">,</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">请注意编辑框内不能有空白字符串</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">.&nbsp;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errors.date={0} </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">日期格式错误，应为</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"> <ST1:CHSDATE w:st="on" isrocdate="False" islunardate="False" day="23" month="3" year="2004">2004-03-23</ST1:CHSDATE> </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">或</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"> 2004-03-23 00:00:00.0 (00:00:00.0 </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">为时</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">:</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">分</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">:</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">秒</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">.</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">毫秒</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">)<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # form1<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; form1.<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">name</span></strong>.displayname=</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">姓名</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; form1.<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">height</span></strong>.displayname=</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">身高</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; form1.<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">born</span></strong>.displayname=</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">出身日期</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">第一、二行不是必须的，但有意义。</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">打包前执行下列批处理</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"> native2ascii ApplicationResources.properties ApplicationResources_zh_CN.properties</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">，目的是由文件</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">ApplicationResources.properties<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">产生新文件</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">ApplicationResources_zh_CN.properties</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">，以便能正确显示汉字，这个新文件也在</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">src/</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">下。</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp; 4</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">、为了验证用户在填写表单时输入的数据，在</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">validation.xml</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">文件的</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&lt;formset&gt;&lt;/formset&gt;</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">之间加入如下内容</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;form&nbsp;&nbsp;&nbsp; name="<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">form1</span></strong>"&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field&nbsp;&nbsp;&nbsp; property="<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">nam</span></strong>e"<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;depends="required"&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;arg0 key="form1.<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">name</span></strong>.displayname"/&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/field&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;field&nbsp;&nbsp;&nbsp; property="<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">height</span></strong>"<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;depends="integer"&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;arg0 key="form1.<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">height</span></strong>.displayname"/&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/field&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field&nbsp;&nbsp;&nbsp; property="<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">born</span></strong>"<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;depends="required,date"&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;arg0 key="form1.<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">born</span></strong>.displayname"/&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;var&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;var-name&gt;datePatternStrict&lt;/var-name&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;var-value&gt;yyyy-MM-dd&lt;/var-value&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/var&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/field&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/form&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp; 5</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">、在</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">jsp</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">页面上，在</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&lt;/body&gt;</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">前加入</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">strus</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">标签</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">:<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;html:javascript formName="<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">form1</span></strong>" dynamicJavascript="true" staticJavascript="true"/&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">经过以上准备，不管是用</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">struts</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">的</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&lt;html:form&gt;&lt;/html:form&gt;</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">标签还是用</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">newxy</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">的</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&lt;nhtml:form&gt;&lt;/nhtml:form&gt;</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">标签，在客户端用户提交数据前都可以进行验证。</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">但如果用</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">struts</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">的</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&lt;html:form&gt;&lt;/html:form&gt;</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">标签，应加入</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">onsubmit</span><font face="宋体"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">事件，如：</span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><O:P></O:P></span></font></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;html:form action="/myAction.do?method=update" onsubmit="return validate<strong><span style="font-family: Verdana; mso-bidi-font-family: 宋体">Form1</span></strong>(this);"&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;html:submit value=" </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">提交</font></span><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"> " /&gt;<O:P></O:P></span></p>
<p style="background: white; line-height: 150%"><span lang="EN-US" style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/html:form&gt;</span></p>
<img src ="http://www.blogjava.net/Mr-Qiu/aggbug/190583.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Mr-Qiu/" target="_blank">Mr.Qiu</a> 2008-04-03 11:55 <a href="http://www.blogjava.net/Mr-Qiu/archive/2008/04/03/190583.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在struts中使用Validator框架</title><link>http://www.blogjava.net/Mr-Qiu/archive/2008/04/03/190563.html</link><dc:creator>Mr.Qiu</dc:creator><author>Mr.Qiu</author><pubDate>Thu, 03 Apr 2008 02:55:00 GMT</pubDate><guid>http://www.blogjava.net/Mr-Qiu/archive/2008/04/03/190563.html</guid><wfw:comment>http://www.blogjava.net/Mr-Qiu/comments/190563.html</wfw:comment><comments>http://www.blogjava.net/Mr-Qiu/archive/2008/04/03/190563.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Mr-Qiu/comments/commentRss/190563.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Mr-Qiu/services/trackbacks/190563.html</trackback:ping><description><![CDATA[Validator验证框架 <br />
Validatro框架以成为Jakarta的公共项目的一部分，可以从http://jakarta.apache.org/commons/下载单独的Validator框架，在Struts中已经呆了这个框架。 <br />
Validator主要依赖两个jar包 <br />
Jakarta-oro.jar:－提供一组处理文本的类，具有文本替换、过滤、和分割功能。 <br />
Commons-validator.jar:提供了一个简单、可扩展的验证框架，包含了通用的验证方法和验证规则。 <br />
<br />
在用Struts中用这个框架，需加入这两个包，用起来感觉还不错。 <br />
下面介绍一下。 <br />
Validator采用基于两个xml文件的方式来配置验证规则，分别为validation.xml，validator-rules.xml。在struts应用中，需放到web-inf目录下。 <br />
<span style="color: red">1．validator-rules.xml</span> <br />
这个文件包含了一组验证规则，对所有struts应用都适用。一般情况不用修改这个文件，除非要修改或扩展默认规则。如果要给应放到另一个xml 文件中，而不是直接添加到validator-rules.xml文件中，这样当Validator升级时，不用修改validator- rules.xml文件。 <br />
<span style="color: red">2．validator.xml文件</span> <br />
这个文件是针对于具体struts应用的，他可以为应用中的ActionForm配置验证规则。 <br />
而不用编码实现验证。 <br />
例如一个验证登陆form的例子，要求用户名必须填写，秘密要求必填、最大、最小长度 <br />
及其内容的要求。<br />
<h3 style="font-weight: bold">
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">&nbsp;1</span><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">&lt;</span><span style="color: #000000">form</span><span style="color: #000000">-</span><span style="color: #000000">validation</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">global</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;!--</span><span style="color: #000000">&nbsp;密码由数字、26个英文字母或者下划线组成的字符串&nbsp;&nbsp;</span><span style="color: #000000">--&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">constant</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">constant</span><span style="color: #000000">-</span><span style="color: #000000">name</span><span style="color: #000000">&gt;</span><span style="color: #000000">pwd</span><span style="color: #000000">&lt;/</span><span style="color: #000000">constant</span><span style="color: #000000">-</span><span style="color: #000000">name</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">onstant</span><span style="color: #000000">-</span><span style="color: #000000">value</span><span style="color: #000000">&gt;^</span><span style="color: #000000">\w</span><span style="color: #000000">+</span><span style="color: #000000">$</span><span style="color: #000000">&lt;/</span><span style="color: #000000">onstant</span><span style="color: #000000">-</span><span style="color: #000000">value</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">constant</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">global</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">formset</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">form&nbsp;name</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">loginForm</span><span style="color: #000000">"</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;!--</span><span style="color: #000000">&nbsp;这里的用户名使用邮箱，验证时使用正则表达式进行验证&nbsp;</span><span style="color: #000000">--&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">field&nbsp;property</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">user.userId</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;depends</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">required</span><span style="color: #000000">"</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">13</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">arg0&nbsp;key</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">user.userId</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">14</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">field</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">15</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">field&nbsp;property</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">user.userPwd</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;depends</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">required,minlength,maxlength,mask</span><span style="color: #000000">"</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">16</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;!--</span><span style="color: #000000">&nbsp;msg&nbsp;name</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">mask</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;key</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">errors.invalid</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/--&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">17</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">arg0&nbsp;key</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">user.userPwd</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">18</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">arg1&nbsp;name</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">minlength</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;key</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">${var:minlength}</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;resource</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">false</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">19</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">arg2&nbsp;name</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">maxlength</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;key</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">${var:maxlength}</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;resource</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">false</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">20</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">var</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">21</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">name</span><span style="color: #000000">&gt;</span><span style="color: #000000">mask</span><span style="color: #000000">&lt;/</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">name</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">22</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">value</span><span style="color: #000000">&gt;^</span><span style="color: #000000">\w</span><span style="color: #000000">+</span><span style="color: #000000">$</span><span style="color: #000000">&lt;/</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">value</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">23</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">var</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">24</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">var</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">25</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">name</span><span style="color: #000000">&gt;</span><span style="color: #000000">minlength</span><span style="color: #000000">&lt;/</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">name</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">26</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">value</span><span style="color: #000000">&gt;</span><span style="color: #000000">6</span><span style="color: #000000">&lt;/</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">value</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">27</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">var</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">28</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">var</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">29</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">name</span><span style="color: #000000">&gt;</span><span style="color: #000000">maxlength</span><span style="color: #000000">&lt;/</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">name</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">30</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">value</span><span style="color: #000000">&gt;</span><span style="color: #000000">20</span><span style="color: #000000">&lt;/</span><span style="color: #000000">var</span><span style="color: #000000">-</span><span style="color: #000000">value</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">31</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">var</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">32</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">field</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">33</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">form</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">34</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">formset</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">35</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000">&lt;/</span><span style="color: #000000">form</span><span style="color: #000000">-</span><span style="color: #000000">validation</span><span style="color: #000000">&gt;</span></div>
<br />
</h3>
<p style="font-weight: bold">validator.xml和validator-rules.xml文件的语法不在这里说明。 <br />
<br />
<span style="color: red">3.Validator插件</span> <br />
为了在struts中用validator，可以用插件方式加载Validator框架， <br />
需在struts配置文件中配置ValidatorPlugIn插件，同时写明两个xml文件的路径。 <br />
应用启动时，Strust会加载这个插件，并调用他的init（）方法，init（）方法根据pathnames加载相应的validator-xml,validator.xml文件，把验证信息读入到内存中。 <br />
</p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">1</span><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">&lt;</span><span style="color: #000000">plug</span><span style="color: #000000">-</span><span style="color: #000000">in&nbsp;className</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">org.apache.struts.validator.ValidatorPlugIn</span><span style="color: #000000">"</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">2</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">set</span><span style="color: #000000">-</span><span style="color: #000000">property&nbsp;&nbsp;&nbsp;&nbsp;value</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml</span><span style="color: #000000">"</span><span style="color: #000000"><br />
</span><span style="color: #008080">3</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">pathnames</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">4</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">plug</span><span style="color: #000000">-</span><span style="color: #000000">in</span><span style="color: #000000">&gt;</span></div>
<span style="color: red">4．Validator和ActionForm</span> <br />
Validator框架不能直接org.apache.struts.action.ActionForm。应采用ActionForm的两个子类 <br />
ValidatorActionForm和ValidatorForm <br />
DynaValidatorActionFrom继续自DynaValidatorForm <br />
支持动态在ActionFrom中使用Validator框架 <br />
ValidatorFormActionForm继承ValidatorForm <br />
支持在标准ActionForm中使用Validator框架。 <br />
<br />
DynaValidtaorForom和ValidatorForm类都实现了validator（）方法，如果验证失败，就会返回包含错误消息的ActionMessage对象，并把该对象添加到ActionErrors集合对象中，由validator方法最后返回ActionErrors对象。 <br />
ValidatorForm有一个子类ValidatorActionForm <br />
ValidatorForm <br />
Strust配置文件的&lt;action&gt;元素的name属------&gt;validator.xml文件&lt;form&gt;元素的name属性 <br />
ValidatorActionForm <br />
Strust配置文件的&lt;action&gt;元素的path属------&gt;validator.xml文件&lt;form&gt;元素的name属性 <br />
Validator框架提供这两个类目的在于可以更加精确的控制执行验证的条件。 <br />
例如 <br />
loginForm表单对应两个验证规则A、B。对应login、cancel两个动作。 <br />
如果对于这两个动作都要执行规则A、B。则可以扩展一个ValidatorFom类loginForm <br />
然后配置 <br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">1</span><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">&lt;</span><span style="color: #000000">formset</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">2</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000">&lt;</span><span style="color: #000000">form&nbsp;name</span><span style="color: #000000">=</span><span style="color: #000000">&#8221;loginForm&#8221;</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">3</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;验证规则A<br />
</span><span style="color: #008080">4</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;验证规则B<br />
</span><span style="color: #008080">5</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />.</span><span style="color: #000000">&lt;/</span><span style="color: #000000">form</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">6</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&#8230;.<br />
</span><span style="color: #008080">7</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000">&lt;/</span><span style="color: #000000">formset</span><span style="color: #000000">&gt;</span></div>
<br />
如果对于用户的login动作，执行规则A。对于cancel动作执行B规则。则可以扩展一个ValidatorActionFom类loginForm <br />
然后配置 <br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">1</span><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">&lt;</span><span style="color: #000000">formset</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">2</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000">&lt;</span><span style="color: #000000">form&nbsp;name</span><span style="color: #000000">=</span><span style="color: #000000">&#8221;login&#8221;</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">3</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;验证规则A<br />
</span><span style="color: #008080">4</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />.</span><span style="color: #000000">&lt;/</span><span style="color: #000000">form</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">5</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000">&lt;</span><span style="color: #000000">form&nbsp;name</span><span style="color: #000000">=</span><span style="color: #000000">&#8221;cancel&#8221;</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">6</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;验证规则B<br />
</span><span style="color: #008080">7</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />.</span><span style="color: #000000">&lt;/</span><span style="color: #000000">form</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;<br />
</span><span style="color: #008080">8</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000">&lt;/</span><span style="color: #000000">formset</span><span style="color: #000000">&gt;</span></div>
<br />
而DynaValidatorForm和DynaValidatorActionForm，区别和ValidatorFrom和ValidatorActionForm的区别一样 <br />
<br />
<span style="color: red">5．在validator框架中使用JavaScript</span> <br />
默认情况下，validator框架在服务器端执行表单验证。也可以在客户端验证。 <br />
如果在客户端验证，需要使用struts的&lt;html:javascript&gt;标签，他能在jsp页面中生成用于客户端验证的JavaScript的脚本。 <br />
1） 在validator－rules.xml文件的&lt;validator&gt;元素中配置&lt;javascript&gt;元素 <br />
默认struts框架的validator－rules.xml文件已经包含了javascript子元素。 <br />
也可以将这些javascript集中放到一个validator.js的文件中，也页面中引入 <br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">1</span><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">&lt;</span><span style="color: #000000">script&nbsp;language</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">Javascript1.1</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;src</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">js/validator.js</span><span style="color: #000000">"</span><span style="color: #000000">&gt;&lt;/</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span></div>
<br />
2） 在Jsp页面中包含&lt;html:javascript&gt; <br />
&lt;html:javascript formName=&#8221;loginForm&#8221;&gt; 这个标签的form的name属性制定需要验证的表单名字，他能够访问为表单配置的验证规则的javascript元素，把包含的脚本写到jsp页面中 <br />
，生成validateLoginForm的函数，负责执行验证逻辑 <br />
3） 对需要验证的表单定义onsubmit事件 <br />
4）<br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">1</span><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">&lt;</span><span style="color: #000000">html:form&nbsp;action</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">manageContract.do</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;onsubmit</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">return&nbsp;validateContractForm(this);</span><span style="color: #000000">"</span><span style="color: #000000">&gt;</span></div>
<br />
5） 用户在表单上提交后，就会调用&lt;html:javascript&gt; <br />
标签生成的js脚本validateLoginForm函数，执行验证。如果验证失败，就会弹出对话框提示，不会提交的服务器端。 <br />
<br />
<span style="color: darkred"><strong>小结</strong></span> <br />
使用步骤 <br />
1）创建扩展ValidatorForm或ValidatorActionForm类的ActionForm，如果使用动态ActionForm，则不用扩展 DynaValidatorForm或DynaValidatorActionForm类的子类，可以直接进行第二步 <br />
2） 在struts文件中配置form和action元素 <br />
3） 把validator框架使用的文本信息添加到应用的Resource Bundle中 <br />
4）<br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">1</span><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">&lt;</span><span style="color: #000000">message</span><span style="color: #000000">-</span><span style="color: #000000">resources&nbsp;parameter</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">com.web.ApplicationResources</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/&gt;</span></div>
<br />
5） 在validatorxml文件中为表单配置验证规则 <br />
6） 在struts配置文件中配置validatorPlugIn插件 <br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">1</span><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">plug</span><span style="color: #000000">-</span><span style="color: #000000">in&nbsp;className</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">org.apache.struts.validator.ValidatorPlugIn</span><span style="color: #000000">"</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #008080">2</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">set</span><span style="color: #000000">-</span><span style="color: #000000">property&nbsp;value</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;property</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">pathnames</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/&gt;</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">plug</span><span style="color: #000000">-</span><span style="color: #000000">in</span><span style="color: #000000">&gt;</span></div>
 <img src ="http://www.blogjava.net/Mr-Qiu/aggbug/190563.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Mr-Qiu/" target="_blank">Mr.Qiu</a> 2008-04-03 10:55 <a href="http://www.blogjava.net/Mr-Qiu/archive/2008/04/03/190563.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>