Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2005

Tip: Looking for answers? Try searching our database.

Getting index from a select object?

Thread view: 
JS - 30 May 2005 19:04 GMT
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?
Fred L. Kleinschmidt - 31 May 2005 16:27 GMT
> I have the following selectbox in my jsp page:
>
[quoted text clipped - 24 lines]
>
> How can it be legal to convert String "myNumber" into an int?

Integer.parseInt(myNumber) is are not converting the string "myNumber"
into an int. It is converting the string stored in parameter myNumber,
which is either "1", "2", or "3".

Signature

Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94  (206)544-5225



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.