Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Validate HTML field on the server  RSS feed

 
paulo cs
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!