Verifying User Input Using JSP Tag Libraries
JSP Views with Validation
Usually to add validation, programmers need a separate JSP page that looks like original form page, but has error messages and is displayed (redirected to) by the server in case the form fields have problems. I simply added error logic in the original JSP page. When the form is displayed for the first time, error checking is not done. On the submit action, the form is submitted onto itself, fields are validated using JSP tags (on the server side, JSPs are compiled into Servlets), and if everything is correct, data is posted to the main Controller Servlet. If not, users will see an error message in the same JSP.
In the JSP page, I have a Java scriplet that creates a boolean flag variable "validate", and sets it to true if there is a "validate" parameter submitted to this JSP.