Validating jsp page
Because many web applications use JSP pages for the view, Struts also provides custom tag libraries which facilitate interaction with HTML forms.
We have a text field in a form that will be used to manually enter the name of a new account.
We need to validate said text field to make sure that the name of the new account does not already exist in Active Directory, in which case we'll alert the user so he/she can change the name accordingly until a new unique account name is found.
Notice that last argument takes the key name for message resources. Another important point to note is that we are adding “customer” attribute to the model, this is necessary to let Spring framework know which model object to use in the form page. Logger Factory; import org.springframework.beans.factory.annotation. Autowired; import org.springframework.beans.factory.annotation. I am using Apache Tomcat 7 and below images show some of the pages with validation error messages.
RUNTIME) public @interface Phone package com.journaldev.validator; import javax.validation. Constraint Validator Context; public class Phone Validator implements Constraint Validator package com.journaldev.validator; import org.springframework.validation. Validation Utils; import org.springframework.validation. Once this method returns, spring framework binds the Errors object to the Binding Result object that we use in our controller handler method. The handler method logic is very simple, if there are any errors we are responding with the same page or else we are redirecting user to the success page. Our application is ready to deploy and run some tests, deploy it in your favorite servlet container.