File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Java String & int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java String & int" Watch "Java String & int" New topic
Author

Java String & int

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 742
I am trying to validate form with Java Servlet.

How can I check in Java that user is giving me String or int??

Thanks & best regards
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

All form fields come in as either java.lang.String (or String[] with getParameterValues).

To insure that a field is numeric, you can either create a regular expression and match it against that or try to convert it to an int with Integer.parseInt from with a try/catch block.
[ March 27, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 742
Originally posted by Ben Souther:
All form fields come in as either java.lang.String (or String[] with getParameterValues).

To insure that a field is numeric, you can either create a regular expression and match it against that or try to convert it to an int with Integer.parseInt from with a try/catch block.

[ March 27, 2008: Message edited by: Ben Souther ]


Can you please get me any regex example?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19794
    
  20



SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java String & int