I have the following selectbox in my jsp page:
<select name="myNumber" >
<option value="1">One
<option value="2">Two
<option value="3">Three
</select>
<%
String myNumber = request.getPara meter("myNumber ");
int n = Integer.parseIn t(myNumber);
%>
With this javacode I am able to store the index of the option choosen from
the select object, in n.
But I think its confusing that converting the name of an option into a int
gives its corresponding value.
Normally that would throw a NumberFormatExc eption:
String z = "Peter";
int k = Integer.parseIn t(z);
throws exception.
How can it be legal to convert String "myNumber" into an int?
<select name="myNumber" >
<option value="1">One
<option value="2">Two
<option value="3">Three
</select>
<%
String myNumber = request.getPara meter("myNumber ");
int n = Integer.parseIn t(myNumber);
%>
With this javacode I am able to store the index of the option choosen from
the select object, in n.
But I think its confusing that converting the name of an option into a int
gives its corresponding value.
Normally that would throw a NumberFormatExc eption:
String z = "Peter";
int k = Integer.parseIn t(z);
throws exception.
How can it be legal to convert String "myNumber" into an int?
Comment