identify data type
I repeat this post in this section, because i think i choose the wrong section before. Sorry....
How can i identify the data type of a variable that is returned by the getParameter method?
suppose there is an int myint=5;
that is submited from an html form, or sent by another page.
i get the variable with request.getParameter("myint")
and ofcourse put it in a String.
How can i check what it was before?
[448 byte] By [
akisa] at [2007-10-3 5:25:30]

You can't know what it was before. You get a String and nothing more.
You can check wether a value can be interpreted as a number and stored in a String:
int i = Integer.parseInt(theString);
If it is can not be interpreted as an integer, you'll get a NumberFormatException that you can catch.
So you have an infinite number of str.equals(<num>) in that if statement?
USe the poster aboves solution of parseInt, like this:
try{
int myInt = Integer.parseInt(str);
}
catch (NumberFormatException nfe)
{
System.out.println("This is not a number");
}
> You can use regular expression to check the string
> pattern. Use match method of String object to check
> this.
>
> [code]
> if (str.match("[0-9]+"){
>// str contains only numeric character.
> /code]
But it does still not solve them problem. The data type that was sent could have been a string containing only digits.
kajbja at 2007-7-14 23:32:42 >
