I have a list of type A, in which each element contains another list of type B. I want to create a form in which when a user selects a value from the drop down list containing values of A, another drop down to populate values based on selected item’s list of Type B. I am new to jQuery but I know that it is convenient to do this using jQuery rather than pure jsp. Please give me a rough outline of steps that I need to follow to get this done.
Share
JSP is just a server side view technology. It doesn’t compete with jQuery. You can perfectly keep using JSP for this. But I understand that you want to fire an asynchronous request using ajaxical techniques rather than a synchronous request. That’s no problem in JSP as well.
First, we need to have two dropdowns in JSP:
Then we need to attach some jQuery to the
changeevent so that it fills the 2nd dropdown based on the value of the 1st dropdown. Add the following to the<script>in JSP or an external script which is loaded through<script src>in JSP:In the servlet behind the
url-patternof/dropdown2optionsjust return the map of options as JSON. You can use Gson for this.That’s basically all.