File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 29220
    
135

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: 60046
    
  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
Struts 1.2 retaininf form fields in jsp in validation error
incompatible: File Upload + Validator Client side JS
STRUTS VALIDATOR FRAMEWORK
Email validation does not work
strut validation frame work issue