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 5991053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:19:55+00:00 2026-05-22T23:19:55+00:00

I have a jsp page. if a user enters a certain text a ajax

  • 0

I have a jsp page. if a user enters a certain text a ajax request is sent and and List is retrieved.Bow i want to built a drop down list from the List object and set the default value to the first element of the List Object. How I can do this.

  • 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-22T23:19:56+00:00Added an answer on May 22, 2026 at 11:19 pm

    I don’t have any AJAX knowledge so I cant help on that end. So my way of solving this would be doing the most I can in java/jsp’s and then using javascript/AJAX to fetch the select from an auxiliary jsp like this:

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <select>
        <c:set var="seenFirst" value="0" />
        <c:forEach var="obj" items="${sessionScope.list}">
            <c:choose>
                <c:when test="${seenFirst == 0}">
                    <c:set var="seenFirst" value="1" />
                    <option value="${obj}" selected>${obj}</option>         
                </c:when>
    
                <c:otherwise>
                    <option value="${obj}">${obj}</option>
                </c:otherwise>
            </c:choose>
        </c:forEach>
    </select>
    

    Edit:
    Actually would be cleaner to build the menu first just with <c:forEach> using an auxiliary var to numerate the options (in the id field), then use javacript to turn on the selected attribute to the first one. Like this:

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <select>
        <c:set var="n" value="0" />
        <c:forEach var="obj" items="${sessionScope.list}">
            <option id="menu-${n}" value="${obj}">${obj}</option>
            <c:set var="n" value="${n + 1}" />
        </c:forEach>
    </select>
    

    And you can use something like this to select the first element:

    var first = document.getElementById('menu-0');
    first.selected = true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .jsp page that the user loads directly. The request it with
I have a jsp page which iterates a list of users. Each user has
I have a jsp page where the user enters their email address and password.
I have a JSP page, which accepts user strings in more than 23 languages.
I have a JSP page, so the user can insert the time when he/she
I have an JSP page where I want to display an image from a
I currently have a JSP page with a Form for the user to enter
I have a jsp page -- let's call it index.jsp. The user clicks on
I am using Ajax in a jsp page wherein we have a form of
I have a jsp page that is trying to reference some user defined classes.

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.