One of the validator validation form instances

Source: Internet
Author: User

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!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.