This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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


JavaRanch » Java Forums » Java » JSP
Bookmark "JSP form validation" Watch "JSP form validation" New topic
Author

JSP form validation

tarun saha
Greenhorn

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
Marshal

Joined: May 26, 2003
Posts: 30580
    
154

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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

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] [Bear's FrontMan] [About Bear] [Books by Bear]
tarun saha
Greenhorn

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.
 
 
subject: JSP form validation