TrainBeaser for iPhone
The moose likes JSP and the fly likes Validate HTML field on the server Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Validate HTML field on the server" Watch "Validate HTML field on the server" New topic
Author

Validate HTML field on the server

paulo cs
Ranch Hand

Joined: Dec 30, 2008
Posts: 34
This is my JSP file:

I have the following function validation cpf (document required in Brazil)


What I need is this: How do I fill in the field to the CPF in the HTML form it is validated by the function that is running on the server. If number entered in the field for a cpf invalid, returns a message and erases the contents, but it goes smoothly.


Paulo Correa, Desenvolvimento de Software, (55 19)8126-8418
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 639
Paulo, your English is rather difficult for me to understand. However, I believe what you are asking is how to validate that the value entered by the user for the "cpf_cnpj" field is correct, and return an error to the user when it is not.

First, your JSP file is not formatted correctly. For example, review the following line:You need an equals sign between name and "nome". It looks like the same error exists in all of the input fields.

For the validation, I would have your JSP page post the information to a Servlet. In the Servlet, you can get the request parameters and validate them as you wish (it's all Java code). If validation fails, you can forward the request back to the original JSP page.

To display an error on the page, you can set a session attribute to indicate the error, then in the JSP page, look for this attribute and if found, display the error. This is made each using JSTL (Java Standard Tag Library).
 
 
subject: Validate HTML field on the server
 
developer file tools