Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2007, 12:44 PM
Registered User
 
Join Date: Aug 2007
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!
 
Old September 4th, 2007, 06:59 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.