This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP form validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP form validation" Watch "JSP form validation" New topic

JSP form validation

tarun saha

Joined: Mar 23, 2010
Posts: 27
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

Joined: May 26, 2003
Posts: 32819

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.)

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

Please read this article to understand how JSP fundamentally works and why you cannot use JSP or servlets to perform client-side validation.

[Asking smart questions] [About Bear] [Books by Bear]
tarun saha

Joined: Mar 23, 2010
Posts: 27
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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: JSP form validation
It's not a secret anymore!