1)Create a new web application
2)Add struts capabilities
3)create new action,form and jsp
4)Add the following lines in Struts-config.xml
//This is for validator plug in
plug-in className="org.apache.struts.validator.ValidatorPlugIn">
set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
and in action tag ,add (validate="true") also.
6)Edit validation.xml
?xml version="1.0" encoding="UTF-8"?>
!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="loginform" >
field property="name" depends="required,minlength" >
arg0 key="err.name" />
arg1 key="${var:minlength}" name="minlength" resource="false" />
var>
var-name>minlength
var-value>3
/field>
field property="pass" depends="required" >
arg0 key="err.pass" />
/field>
/form>
/formset>
/form-validation>
7)Edit Form JSP
html:javascript formName="loginform"/>
html:form action="login" onsubmit="return validateLoginform(this)">
onsubmit return validateFormName(this).
8)Test your application
Thanks
deepak
No comments:
Post a Comment