It's not a secret anymore!
The moose likes EJB and other Java EE Technologies and the fly likes drop down values in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "drop down values in jsp" Watch "drop down values in jsp" New topic

drop down values in jsp

Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
hello all,
what is the best way to retreive the drop down data from the database to display in a jsp in a 3 tier env? what abt the dependent drop downs.?

You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Greg Charles

Joined: Oct 01, 2001
Posts: 2962

You really can't do anything fundamentally different with JSP from what you can do with HTML. You still make your drop down box with HTML form elements, but instead of hard-coding the values, you can pull them from a database or something. You can use Java Script to populate dependant drop downs dynamically.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
If you're using an MVC style architecture then you could retrieve the contents of the lists from the database, and place it request scope ready to be rendered by the JSP view. This rendering could be implemented using a view helper such as a custom tag.
Check out Chapter 8 of my book (in PDF format) that has an example custom tag to help render drop downs. Say that you have a collection of JavaBeans in that collection representing countries, the tag takes the name of the bean properties that will be used for the key and display values (e.g. country ID and name), and uses Java's reflection mechanism to access them.
Hope it's useful...
I agree. Here's the link:
subject: drop down values in jsp
It's not a secret anymore!