1. Add the following in the struts-config.xml: Code
< Plug-in Classname = "Org. Apache. Struts. validator. validatorplugin" >
< Set-Property Property = "Pathnames" Value = "/Org/Apache/struts/validator/validator-rules.xml,/WEB-INF/validations. xml" />
</ Plug-in >
2. Create validations. xml under the WEB-INF. Assume that the verified form is named inputform, the verification name, title, content cannot be blank, the Code is as follows:
<? XML version = "1.0" encoding = "UTF-8" ?>
<! Doctype form-validation public
"-// Apache Software Foundation // DTD commons validator rules configuration 1.3.0 // en"
Http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd" >
< Form-validation >
< FormSet >
< Form Name = "Inputform" >
< Field Property = "Name" Depends = "Required" >
< MSG Name = "Required" Key = "Guest. inputform. Name" />
</ Field >
< Field Property = "Title" Depends = "Required" >
< MSG Name = "Required" Key = "Guest. inputform. Title" />
</ Field >
< Field Property = "Content" Depends = "Required" >
< MSG Name = "Required" Key = "Guest. inputform. Content" />
</ Field >
</Form>
</FormSet>
</Form-validation>
3. Set the resource file for display information
Guest. inputform. content = content is null
Guest. inputform. Name = Name Is null
Guest. inputform. Title = title is null
4. Add <HTML: javascript formname = "inputform"/> in front of the JSP file and modify <HTML: Form Action = "/input">, change to <HTML: Form Action = "/input" onsubmit = "Return validateinputform (this)">