Getting index from a select object?



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.getParameter("myNumber");
int n = Integer.parseInt(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 NumberFormatException:

String z = "Peter";
int k = Integer.parseInt(z);

throws exception.

How can it be legal to convert String "myNumber" into an int?



.



Relevant Pages

  • Re: Adding large numbers in C
    ... one of the numbers - or perhaps the result - is too big to store in an int. ... you have bitstrings longer than 8 bits, simply use an array of unsigned ... Incidentally, the subtraction routine does similar juggling, so if M and N ...
    (comp.lang.c)
  • Re: read keyboard input and storing in an array?
    ... > I'm trying to store user input in an array, ... You have the beginnings of that logic already since your prompt tells the ... 201st value since the array only has room for 200 values. ... This will force you to store the int values as Integer ('Integer' ...
    (comp.lang.java.help)
  • Re: attempting an actual game...
    ... > be used to store a colour definition rather than an index? ... if I were you and wanted to get to a finished game I ... ugly bitmasking teqniques and similar can sometimes save effort over more ... >>> (I once started with typedef int Cell, with a view to making a Cell ...
    (comp.games.development.programming.misc)
  • Re: Basic questions
    ... The compiler is allowed to insert padding bits wherever it likes ... > As 16 is an int, what you wrote is equivalent to ... if the OP uses 'unsigned short' only to store 16-bit numbers (writing ... values, so they're not a panacea for portability, and they might trick ...
    (alt.comp.lang.learn.c-cpp)
  • Re: attempting an actual game...
    ... >>> and inflexible by the absurd decision to use a bit array for square ... as then one has 8 bits in which to store a color and a few flags ... Using a 2D int (or, ... > Change direction and you may eventually complete a game. ...
    (comp.games.development.programming.misc)