Populating cascading dropdown lists in JSP/Servlet

后端 未结 4 1444
[愿得一人]
[愿得一人] 2020-11-22 03:32

Suppose I am having three dropdownlist controls named dd1, dd2 and dd3. The value of each dropdownlist comes from database. dd3<

4条回答
  •  一生所求
    2020-11-22 04:31

    You may need multiple servlets for this.

    Servlet 1: Load the values for the first drop down list from the database. On the JSP page construct the drop down list. On the user selecting a value submit to servlet two.

    Servlet 2: retrieve the value from the first list and perform your database search for the values of the second list. Construct the second list. When the user selects the second value submit it to servlet 3.

    Servlet 3: retrieve the value selected in the second drop down and perform the database search to get values for the last drop down.

    You may want to consider AJAX to make the populating of the lists appear seamless to the users. jQuery has some very nice plugins for making this quite easy if you are willing to do that.


         

    You can write JavaScript that submits the form in the onchange event. Again, If you use an existing library like jQuery it will be 10 times simpler.

提交回复
热议问题