Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 11th, 2007, 12:44 PM
Registered User
Join Date: Aug 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create a drop down list using database values

Hi. I just started studying JSP and I need help creating a drop down list that would use database (Access/SQL) information for the options.

example table would be:

Names Number
erin 1
keira 2
jack 3
april 4

I would use the Names (erin, keira, etc) for the drop down list. And also, I would have to use the names and pass the value of the selected name to the page that would process the data.

Thank you!
Reply With Quote
  #2 (permalink)  
Old September 4th, 2007, 06:59 AM
Friend of Wrox
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post

Do as follows
1. Call a servlet which will query the db and get the rows in the table and generates an ArrayList object with the names and values [For example a bean called NameValuesBean which will have one integer and one String objects and getter and setter method for it]. For every row you'll create an instance of a custom bean [NameValuesBean] and add them to the ArrayList.
2. Set the this arrayList to the request attribute and forward to the jsp.
3. In the JSP get the request attribute and and loop through the ArrayList in the jsp and generate the <option> tags with the name and values.

Thats it your done.

- Rakesh
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database/Drop Down list help jackiew Classic ASP Databases 4 July 30th, 2007 03:48 PM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Retrive values to Drop down list from DB when Back choudhmh Pro VB.NET 2002/2003 0 January 12th, 2005 10:44 AM
Create drop down list from SQL DB lshamba Classic ASP Databases 2 August 26th, 2004 10:49 PM

All times are GMT -4. The time now is 07:41 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.