用struts进行验证时无法进行invalid与email验证
ApplicationResources.properties文件内容errors.required={0} is not should be blank!
namelab=Name
errors.range={0} is not in the range {1} through {2}.
agelab=Age
errors.email={0} is an invalid e-mail address.
emailab=Email
errors.invalid={0} is invalid.
telab=Tel
validation.xml文件内容
<!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>
<formset>
<form name="regForm">
<field property="uname" depends="required,mask">
<arg0 key="namelab"/>
<var>
<var-name>mask</var-name>
<var-value>[A-Za-z]</var-value>
</var>
</field>
<field property="age" depends="required,intRange">
<arg0 key="agelab"/>
<arg1 name="intRange" key="${var:min}" resource="false"/>
<arg2 name="intRange" key="${var:max}" resource="false"/>
<var>
<var-name>min</var-name>
<var-value>5</var-value>
</var>
<var>
<var-name>max</var-name>
<var-value>150</var-value>
</var>
</field>
<field property="email" depends="email">
<arg0 key="emailab"/>
</field>
<field property="tel" depends="required, mask">
<arg0 key="telab"/>
<var>
<var-name>mask</var-name>
<var-value>^\d{3}(-\d{8})?$</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
前台页面:
<%@ page language="java" pageEncoding="GB18030"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
<title>JSP for RegForm form</title>
</head>
<body>
<html:form action="/reg">
uname : <html:text property="uname"/><html:errors property="uname"/><br/>
sex : <html:text property="sex"/><html:errors property="sex"/><br/>
age : <html:text property="age"/><html:errors property="age"/><br/>
email : <html:text property="email"/><html:errors property="email"/><br/>
tel : <html:text property="tel"/><html:errors property="tel"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
错误信息:
java.lang.NoClassDefFoundError: org/apache/oro/text/perl/Perl5Util
org.apache.commons.validator.GenericValidator.matchRegexp(GenericValidator.java:65)
org.apache.struts.validator.FieldChecks.validateMask(FieldChecks.java:233)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:544)
org.apache.commons.validator.Field.validateForRule(Field.java:796)
org.apache.commons.validator.Field.validate(Field.java:876)
org.apache.commons.validator.Form.validate(Form.java:288)
org.apache.commons.validator.Validator.validate(Validator.java:351)
org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:116)
org.apache.struts.chain.commands.servlet.ValidateActionForm.validate(ValidateActionForm.java:58)
org.apache.struts.chain.commands.AbstractValidateActionForm.execute(AbstractValidateActionForm.java:120)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
错误情况:能够进行required和intRange 但是email和mask验证 输入正确和错误都会显示上述错误
搜索更多相关主题的帖子:
invalid struts email errors range
----------------解决方案--------------------------------------------------------
缺少一个jakarta-oro.jar 包,需要自己去下载。下过来以后把它加到你的lib里面就可以了。
----------------解决方案--------------------------------------------------------