Posted on 2007-08-09 12:03
G_G 阅读(1470)
评论(0) 编辑 收藏 所属分类:
struct
问题:
当IE 禁用javascript 怎么验证数据
解决:Struts validation 框架
1)先 建 Form类
extendsValidatorForm
private String name ;
private String pass ;
2) Jsp 建立
<body>
<font color="red" ><html:errors/></font>
<html:form action="/test">
name:<html:text property="name" />
pass:<html:text property="pass" />
<html:submit>submit</html:submit>
</html:form>
</body>
3)validator.xml建立
<?xml version='1.0'?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
<form-validation>
<formset>
<form name="testForm">
<field property="name" depends="minlength,maxlength,mask">
<msg name="minlength" key="err.minlength" />
<!-- 当 minlength错时 msg 激活 -->
<msg name="maxlength" key="err.maxlength" />
<arg0 key="${var:maxlength}" resource="false"/>
<arg1 key="${var:minlength}" resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>5</var-value>
</var>
<var>
<var-name>minlength</var-name>
<var-value>3</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
4)ApplicationResources.properties
# Resources for parameter 'com.validator.struts.ApplicationResources'
# Project P/validator
err.minlength= err min < 3
err.maxlength= err max > 5
心得: validation 这是个难啃的骨头 要多多的接触