File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Populating an HTML option list from a resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Populating an HTML option list from a resultset" Watch "Populating an HTML option list from a resultset" New topic
Author

Populating an HTML option list from a resultset

Kevin Currie
Greenhorn

Joined: Feb 02, 2004
Posts: 2
Hi,
Anyone know how to populate an HTML form option list from a JDBC resultset?
Thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56192
    
  13

Here's my version of the 2,679 ways this could be done: (in other words, here's how I'd do it):
1) The controller servlet for the request would interact with a model-level class that abstracts the list. Returned would be an array list or other structure containing the name-value pairs for the options list. The JDBC is completely performed in the model class.
2) The controller would place this list on the request as an attribute, then forward to the JSP page for the view.
3) The JSP page would use the JSTL forEach tag to iterate over the list and construct the HTML for the options.
Notice that each tier of the MVC architecural patterm comes into play.
[ February 16, 2004: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 852
One of several FormattedDataSet signatures available. Others take ResultSet's and display multiselect, and regular listboxes.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Populating an HTML option list from a resultset
 
Similar Threads
how to display values from database in a dropdown box?
2 Select Box`s on one page, second needs to load dynamically
Urgent!!
question about struts' html:options tag
Forward only ResultSet