Posted on 2011-06-30 11:32
鲨鱼的微笑 阅读(239)
评论(0) 编辑 收藏
struts-config.xml
<form-bean name="userForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="username" type="java.lang.String" />
<form-property name="password" type="java.lang.String" />
</form-bean>
增加的一条配置
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
生成的validation配置
<formset>
<form name="userForm">
<field property="username" depends="required">
<arg0 key="label.username" resource="true" />
</field>
<field property="password" depends="required">
<arg0 key="label.password" resource="true" />
</field>
</form>
</formset>
ApplicationResouce的配置
label.username=username
label.password=password
errors.required={0} is required.
jsp里需要添加的语句
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html:form action="/user" onsubmit="return validateUserForm(this);">
username : <html:text property="username"/><html:errors
property="username"/><br/>
password : <html:text property="password"/><html:errors property="password"/><br/>
<html:submit/><html:cancel/>
</html:form>
<html:javascript formName="userForm"/>