> Just want to create an html select object with options set to the contents > of a database table - i.e. visualise > a lookup table. So when the form is first displayed the dropdown appears > with data from a database table. > I'm confused where the database access should go - in the JSP or the > FormBean. Is there an example which > someone could point me to
I do this in a ServletContextListener, because the contents of my dropdowns are the same for all users. I put several Maps in application scope and reuse them. If you need to customize the contents for each user, then this wouldn't be appropriate. But even the Listener has no database specific code-- that's all in a DAO layer: http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.ht ml This may look overwhelming, but it's in your own best interest to *not* put database specific code into your Actions (and never in the JSP or in the Form bean). At the very least, make a single separate class and put all the database access code (JDBC?) in there. Perhaps you would have a method like getDropdownContents() that returns a Map. You can then put this Map in request scope and use it to populate the drop-down list. Finding an example will be hard. They all say, "In a real application we wouldn't do this, but for the purposes of this example..." and then they proceed to do exactly what you shouldn't do! But everyone's database and data structures are so different that it's difficult to come up with the one "right" way of doing things. -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University PA Information Resources Management