aspose 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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 726
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: 726
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: 19554
    
  16



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
 
Similar Threads
Get more error in the below program
How to convert string to int ?
check the output
string UTF8
how to read speific lines in a text file