Please help me regarding JSP

I have two combo boxes in the jsp page.i want to do that on selection of the value of the first combo box it fills the second combo box. the values in both combo boxes are from Databaseso please help me
[223 byte] By [sac_rose923a] at [2007-10-3 1:10:00]
# 1

I'm guessing that what you are trying to do is a category, subcategory type arrangement where selecting an option in the first CB changes the options in the second. You have a couple of options here. One is to use jax to dynamically gather the data for the second CB. Or you could populate an associative javascript array in the page such that changing the value in the first CB selects an array of values from the list to populate the second CB with.

The second option will work only if the possible CB1/CB2 combinations is relatively small as you have to predownload all your data to the client. The first option is significantly more complicated to implement.

A third option is to have the form submit upon changing the first CB, with the resultant JSP populating the second CB. This complicates your state management a little bit but is pretty straightforward to implement.

I don't use JSF (Java Server Faces) or Struts (I use my own MVC implementation) but one or both of them probably have something to simplify this for you. It might be worth your time to look into them.

Outtascopea at 2007-7-14 18:06:53 > top of Java-index,Java Essentials,Java Programming...
# 2
thanks for u r replyI tried third option by u but it can't work, so plz explain me with some code snippest
sac_rose923a at 2007-7-14 18:06:53 > top of Java-index,Java Essentials,Java Programming...
# 3

it's much more than code snippets.

if you have a front controller servlet, which you can do with or without struts, you have the request go to the servlet, put a List with data into request scope for the second drop down, and forward back to the originating page.

you'll have to do some work, because it's not snippets.

try it with a small example: one jsp, one servlet.

%

duffymoa at 2007-7-14 18:06:53 > top of Java-index,Java Essentials,Java Programming...
# 4

I think the best solution is to use javascript like the following :

look at this example :

http://www.java2s.com/Code/JavaScript/Form-Control/ChangingSelectElementContenttwoCombobox.htm

try to mix javascript and java in your jsp to create the items of your combo boxes.

so, data is collected when your jsp is transformed into html and sent to client.

when user change one combo box, the related combo box contents are changed using javascript (on the client side).

hth

java_2006a at 2007-7-14 18:06:53 > top of Java-index,Java Essentials,Java Programming...