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

  • Home
  • SEARCH
  • 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 5959187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:38:59+00:00 2026-05-22T18:38:59+00:00

This thing is really bothering me. How can I get my dropdown list from

  • 0

This thing is really bothering me. How can I get my dropdown list from MySQL database and then submit it to another table in JSP. I only know how to create a static dropdown with html and but how can I make it dynamic. I am thinking of a form that links to a servlet and the servlet connects to the database and fetches an array of strings from a database table and then sends it to the JSP to populate the options and when an option is submitted, it send to a servlet which then inserts to the database. someone please give me some sample code that can do this. Most specifically I need the code of the JSP used in the tag and the code for sending from the servlet. I’ve really checked with google but there is no clear answer. Hope I get an answer here

  • 1 1 Answer
  • 0 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-22T18:39:00+00:00Added an answer on May 22, 2026 at 6:39 pm

    You’ve it almost right. To get the dropdown values from a database you should first call the servlet which does the preprocessing job and then let the servlet display the JSP with the dropdown.

    Since a normal HTTP request (clicking a link, a bookmark or entering the URL in address bar) fires per definition a GET request, you’d like to do the job in the doGet() method. Here’s an example which gets the dropdown values in flavor of a List<Product>.

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Product> products = productService.list();
        request.setAttribute("products", products); // It'll be available as ${products}.
        request.getRequestDispatcher("/WEB-INF/products.jsp").forward(request, response);
    }
    

    In /WEB-INF/products.jsp you can display it as follows:

    <form action="order" method="post">
        <select name="productId">
            <c:forEach items="${products}" var="product">
                <option value="${product.id}">${product.name}</option>
            </c:forEach>
        </select>
        <input type="submit" value="Order" />
    </form>
    

    Map this servlet on an URL pattern of /products and invoke it by http://example.com/context/products. It’ll load the products from the DB, store it in the request scope, forward to the JSP to let it present it.

    When you submit the form, then the doPost() method of a servlet which is mapped on an URL pattern of /order will be invoked. When you submit a HTML form, then the name=value pair of every input element will be available as a HTTP request parameter. So you can get the product ID as follows:

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String productId = request.getParameter("productId");
        // ... do your job here to insert the data.
    
        request.getRequestDispatcher("/WEB-INF/someresult.jsp").forward(request, response);
    }
    

    See also:

    • Our JSP wiki page
    • Our Servlets wiki page
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be a really really simple thing, but for some reason it is
This is the one thing I could never get to work. My problem is
This thing really bugs me: on http://view.jquery.com/trunk/plugins/autocomplete/demo/ , how come the text in the
This thing has given me a really bad headache. I'm trying to load a
OK, so I couldn't really think of an apropos title that summarizes this. The
This is a self-explanatory question: Why does this thing bubble into my try catch's
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I've run across this sort of thing on multiple websites and was wondering what
Here's a coding problem for those that like this kind of thing. Let's see
I'm trying to do a simple update. I've done this kind of thing thousands

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.