This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

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: 60816
    
  65

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSP form validation
 
Similar Threads
incompatible: File Upload + Validator Client side JS
Email validation does not work
strut validation frame work issue
Struts 1.2 retaininf form fields in jsp in validation error
STRUTS VALIDATOR FRAMEWORK