1 ActionForm中的validate方法验证
1)重写ActionForm中的validate方法
public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){
ActionErrors errors=new ActionErrors ();
if(username==null || username.length()<0){
errors.add("unameisnull",new ActionMessgae("error.validate.unull"));
}
return errors;
}
2)资源文件ApplicationResources.properties
error.validate.unull=usernaem is null
3)在config.xml的<action-mappings>中<action>加入validate="true"属性
4)页面标签
<html:errors/>
----------------------------------------------------
validate验证框架
1 创建form继承ValidatorForm或用DynaValidatorForm
2 在WEB-INF下创建validator-rules.xml和validation.xml
3 在src下创建资源文件ApplicationResources.properties
4 要struts-config.xml中配
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
5 编写validation.xml文件
<formset>
<form name="userForm">
<field property="username" depends="required">
<arg key="lable.username"/>
</field>
</form>
</formset>
6 页面使用<html:errors/>标签
posted on 2009-11-30 08:15
junly 阅读(479)
评论(0) 编辑 收藏 所属分类:
struts2/struts1.3/JSF