What is Struts 2 RequiredFieldValidator?
Need an Example or Code on Field Validation in Struts 2.
Please follow the following instruction: 1. index.jsp <ul> <li><a href="roseindia/requiredFieldValidatorError.action">RequiredFieldValidator Example</a></li> </ul> 2. struts.xml <action name="requiredFieldValidatorError"> <result>/pages/chatQuestion/requiredFieldValidatorError.jsp</result> </action> <action name="requiredFieldValidatorError1" class="net.roseindia.requiredFieldValidatorAction"> <result name="input">/pages/chatQuestion/requiredFieldValidatorError.jsp</result> <result name="error">/pages/chatQuestion/requiredFieldValidatorError.jsp</result> <result name="success">/pages/chatQuestion/requiredFieldValidatorSuccess.jsp</result> </action> 3. requiredFieldValidatorError.jsp <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>RequiredFieldValidator Example!</title> <link href="<s:url value="/css/main.css"/>" rel="stylesheet" type="text/css"/> <s:head theme="ajax" /> <s:actionerror/> </head> <body> <s:form name="validate" action="requiredFieldValidatorError1" method="POST" validate="true"> <s:textfield name="username" label="Username"/> <s:password name="password" label="Password"/> <s:submit value="Submit" /> </s:form> </body> </html> 4. requiredFieldValidatorSuccess.jsp <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>RequiredFieldValidator Example!</title> <link href="<s:url value="/css/main.css"/>" rel="stylesheet" type="text/css"/> </head> <body> Username: <s:property value="username" /><br> Password: <s:property value="password" /> </body> </html> Whenever user don't input any data then it displays an error. If you enter username and password then you get your username and password in requiredFieldValidatorSuccess.jsp.
Ads