Validator verification framework first creates a file named validation. XML (this name is required) under the WEB-INF folder.
Validation. xml file
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype form-validation public
"-// Apache Software Foundation // DTD commons validator rules configuration 1.1.3 // en"
Http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd>
<Form-validation>
<Global>
<Constant>
<Constant-Name> phone </Constant-Name>
<Constant-value> ^/d {8 }$ </Constant-value>
</Constant>
</Global>
<FormSet>
<Form name = "userform">
<Field property = "username" depends = "required">
<! -- Depends in field indicates the method defined in validator-rulers.xml -->
<MSG name = "required" Key = "username" resource = "true"/>
<! -- In MSG, resource indicates whether to read the prompt information from the properties file. -->
</Field>
<Field property = "userpwd" depends = "required, minlength">
<MSG name = "required" Key = "Mima Bu Neng Wei Kong! "
Resource = "false"/>
<MSG name = "minlength" Key = "Chang du Bu Neng Xiao Yu 5! "
Resource = "false"/>
<Var>
<Var-Name> minlength </var-Name>
<Var-value> 5 </var-value>
</Var>
</Field>
<Field property = "userpwd" depends = "required">
<MSG name = "required" Key = "Mima Bu Neng Wei Kong! "
Resource = "false"/>
</Field>
</Form>
</FormSet>
</Form-validation>
JSP page
<% @ Page Language = "Java" pageencoding = "gb2312" %>
<% @ Taglib uri = "http://jakarta.apache.org/struts/tags-bean" prefix = "Bean" %>
<% @ Taglib uri = "http://jakarta.apache.org/struts/tags-html" prefix = "html" %>
<HTML>
<Head>
<Title> JSP for userform </title>
</Head>
<Body>
<% -- <HTML: Form Action = "/user"> -- %>
<% -- Username: <HTML: Text property = "username"/> <HTML: errors property = "username"/> <br/> -- %>
<% -- Userpwd: <HTML: Text property = "userpwd"/> <HTML: errors property = "userpwd"/> <br/> -- %>
<% -- <HTML: Submit/> <HTML: cancel/> -- %>
<% -- </Html: Form> -- %>
<HTML: Form Action = "/user">
Username: <HTML: Text property = "username"/> <HTML: errors property = "username"/> <br/>
Userpwd: <HTML: Text property = "userpwd"/> <HTML: errors property = "userpwd"/> <br/>
<HTML: Submit/> <HTML: cancel/>
</Html: Form>
</Body>
</Html>
Applicationresources. properties File
# Resources for parameter 'com. yourcompany. Struts. applicationresources'
# Project validatetest
Username = yonghumingbunengweikong!