Basic issues should be noted when using Validator verification in Struts development

xiaoxiao2021-03-06  37

Using Validator verification in Struts development is the basic problem that should be considered

First, in the last position in the struts-config.xml, plus

with

Value = "/ Web-inf / validator-rules.xml, / web-inf / value.xml" />

Among them, Validator-rules.xml is used to define verification rules, and validation.xml is used to set the table item that needs to be defined, and what information is to be verified, what information is returned when the error is wrong. ApplicationResources is the resource file for the error message to display. Examples are as follows:

Validator-rules.xml:

"- // Apache Software Foundation // DTD Commons Validator Rules Configuration 1.0 // En"

"http://jakarta.apache.org/commons/dtds/Validator_1_0.dtd">

ClassName = "org.apache.struts.validator.fieldchecks"

Method = "ValidateRequired"

Methodparams = "java.lang.object,

Org.apache.commons.valiDator.validatorAction,

Org.apache.commons.validator.field,

Org.apache.struts.Action.Actionerro,

Javax.Servlet.http.httpservletRequest "

Msg = "ErrorS.Required">

The MSG is an error to display when "required" verification fails.

VALIDATION.XML:

Depends = "Required">

ARG0 is an error message to be added when the different Property verification fails

Depends = "Required">

ApplicationResources.Properties:

# Resources for parameter 'com.ln.struts.ApplicationResources'

# Project P / Struts

Errors.Header =

Errors.footer =

Error.Name = a username

Error.Password = a Password

Errors.Required = {0} is Required

Then use it on the page

It is said that it is said. (Note: The Property here is consistent with the field's property value in validation.xml).

转载请注明原文地址:https://www.9cbs.com/read-66130.html

New Post(0)