Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 822965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:52:34+00:00 2026-05-15T02:52:34+00:00

I have a list of type A, in which each element contains another list

  • 0

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.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:52:35+00:00Added an answer on May 15, 2026 at 2:52 am

    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:

    <select id="dropdown1">
        <c:forEach items="#{bean.items}" var="item">
            <option value="#{item.value}">#{item.label}</option>
        </c:forEach>
    </select>
    <select id="dropdown2">
        <option>Please select dropdown1</option>
    </select>
    

    Then we need to attach some jQuery to the change event 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:

    $(document).ready(function() {
        $('#dropdown1').change(function() {
            var selectedValue = $(this).val();
            var servletUrl = 'dropdown2options?value=' + selectedValue;
    
            $.getJSON(servletUrl, function(options) {
                var dropdown2 = $('#dropdown2');
                $('>option', dropdown2).remove(); // Clean old options first.
                if (options) {
                    $.each(opts, function(key, value) {
                        dropdown2.append($('<option/>').val(key).text(value));
                    });
                } else {
                    dropdown2.append($('<option/>').text("Please select dropdown1"));
                }
            });
        });
    });
    

    In the servlet behind the url-pattern of /dropdown2options just return the map of options as JSON. You can use Gson for this.

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String selectedValue = request.getParameter("value");
        Map<String, String> options = optionDAO.find(selectedValue);
        String json = new Gson().toJson(options);
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(json);
    }
    

    That’s basically all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object of type list from which I wish to use to
I have a list which contains some items of type string. List<string> lstOriginal; I
I have a generic chart type which contains points as List<double> . How can
I have a list of type stored procedure which have an ID and a
I have a List<T> where T is my Event type which has a field
I have a list of items of type ViewLookupItem which has these properties: For
I have an std::list<TYPE> which may contain child classes of TYPE. I need to
I have a list of type IList<Effort> . The model Effort contains a float
I have an array of type string which I want to re-use inside a
I'm new to python, and have a list of longs which I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.