Posted on 2007-08-09 12:03
G_G 閱讀(1474)
評(píng)論(0) 編輯 收藏 所屬分類:
struct
問題:
當(dāng)IE 禁用javascript 怎么驗(yàn)證數(shù)據(jù)
解決: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"?/>?
??????????????? <!-- 當(dāng) minlength錯(cuò)時(shí) 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? 這是個(gè)難啃的骨頭 要多多的接觸