Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP form validation

 
tarun saha
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well im new to jsp...

I wanted to know what is the best way to validate a jsp form at client side, like checking if any mandatory field is left empty or having invalid data.
For example i have an input type=file and on hitting the submit button i want to validate the file input field is left empty. Then should i use any inbuilt function(if available in jsp) or use scriptlet?

Please teach me how can i use scriptlets for this purpose, like the necessary library files and the class needed to be imported.

Thank you for any help in advance.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34681
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tarun,
You would use JavaScript to do client side validation. Scriptlets would not help because they run with the HTML is rendered rather than after it is already on the client.

Note that you still need to validate again in Java (such as the servlet) since anything done on the server can be hacket.)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64985
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this article to understand how JSP fundamentally works and why you cannot use JSP or servlets to perform client-side validation.
 
tarun saha
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much to you guys, javascript worked superb and is very short also.

And thank you for the article. now im clear with the concepts.

Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic