开发者

sample code for Dynamically populating dropdown in JSP [duplicate]

This question already has answers here: Populating cascading dropdown lists in JSP/Servlet (4 answers) Closed 6 years ago.

I have two dropdowns in my form. The first one Queries for a set of data and displays them. Based on the value selected in the first dropdown i have to query the database, using that selected value as a parameter and populate the second dropdown. In short, based on the first dropdown, second one has to be populated dynamically. Am coding in JSP. Please do help on this!

T开发者_如何学编程hanks, Geetha


You can do this in 3 ways:

  1. Submit the form to the server side and let the JSP/Servlet load and display the child dropdown accordingly based on the request parameter. Technically the simplest way, but also the least user friendly way. You probably also want to revive all other input values of the form.

  2. Let JSP populate the values in a JavaScript array and use a JavaScript function to load and display the child dropdown. A little bit trickier, certainly if you don't know JavaScript yet, but this is more user friendly. Only caveat is that this is bandwidth and memory inefficient when you have relatively a lot of dropdown items.

  3. Let JavaScript fire an asynchronous HTTP request to the server side and display the child dropdown accordingly. Combines the best of options 1 and 2. Efficient and user friendly.

I've posted an extended answer with code samples here: Populating child dropdownlists in JSP/Servlet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜