html form that contains a list of options drawn from db
Edmund Castermund
Ranch Hand
Joined: May 09, 2007
Posts: 77
posted
0
Hi,
I'm creating an html form, and the user will select options from a pulldown list. The content of that list will need to be drawn from the data base.
Is it best to have the form contained in a servlet? And then the action attribute of the form will be another servlet? Since most of the form is static (other than the list contents) I thought it made sense to do this as a .jsp file.
Can I grab the list contents with a scriptlet?
bp
There are a number of ways to pull this off. While ideally you should separate your view to JSP and your control & data gathering to servlet, the Java Standard Tag Libraries provide a quick-and-dirty way to pull the data & display it all within the JSP.
What I find is a more important question with these lists is "how often does this data change?". If you use the quick-and-dirty JSTL sql tags, every page request results in another query of the database, which might be overkill. I have a number of apps that must display a drop-down list of departments, which change infrequently (maybe every six months). In these cases, I will frequently use an application scope List, and then use a Filter to make sure the List is set, and up-to-date. I am attaching source code from one of my filters for your benefit (or at least I would, if I knew how to use attachments on this forum).
OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Pete Nelson wrote:Java Standard Tag Libraries provide a quick-and-dirty way to pull the data & display it all within the JSP.
The emphasis here is on "quick and dirty". Even the JSTL Specification says not to use these tags in anything but test code or where there are no alternatives.