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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:08:52+00:00 2026-06-10T20:08:52+00:00

I have a problem with a taglib method c:forEach. I want to get a

  • 0

I have a problem with a taglib method c:forEach. I want to get a List of languages from a servlet class and show it on a jsp page with c:forEach. But it is just showing nothing^^ an empty select tag.

The for each loop in the jsp file (i have taglib import and already tried without c:out):

...
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
...
<c:forEach var="lang" items="${registrationServlet.inputLangs}">
  <option><c:out value="${lang}"></c:out></option>
</c:forEach>

My Servlet Class (it is a servlet because I have to do some form submitting stuff with it too):

...
// List of languages to choose from
List<String> inputLangs;
...
// Query the languages from the database
public List<String> getInputLangs() {
    try {
        String query = "SELECT DISTINCT Lang FROM country";
        ResultSet result = DbConnection.read(query);
        while (result.next()) {
            inputLangs.add(result.getString("lang"));
        }
    } catch (SQLException e) {
        System.err.println("Couldn't get languages from DB.");
    }
    return inputLangs;
}

What am I doing wrong?^^

BTW. it works with pure java:

<%
RegistrationServlet reg = new RegistrationServlet();
for (String lang : reg.getInputLangs()) {
%>
  <option><%=lang%></option>
<%
}
%>

But as far as I know that’s a no go in jsp files 😉

  • 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-06-10T20:08:54+00:00Added an answer on June 10, 2026 at 8:08 pm

    ${registrationServlet.inputLangs} means:

    • find an attribute named “registrationServlet” in the page scope
    • if not found, find an attribute named “registrationServlet” in the request scope
    • if not found, find an attribute named “registrationServlet” in the session scope
    • if not found, find an attribute named “registrationServlet” in the application scope
    • if found, call getInputLangs() on the found object

    So, if you haven’t stored any instance of RegistrationServlet in any scope, this expression will always evaluate to null. If you keep this design, the doGet() (or doPost()) method of your servlet should have the following line:

    request.setAttribute("registrationServlet", this);
    

    But it would be much cleaner to have

    request.setAttribute("inputLangs", getInputLangs());
    

    and, in the JSP:

    <c:forEach var="lang" items="${inputLangs}">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement custom JSP list tag, but have problem with accessing properties
I have problem with .css file on my JSP page. My page looks like
I have a jsp-page <%@page import=org.springframework.web.servlet.ModelAndView%> <%@page import=mvc3.helpers.Utils%> <%@ page language=java contentType=text/html; charset=UTF-8 pageEncoding=UTF-8%>
I have jsp file: <%@ page language=java contentType=text/html; charset=UTF-8 pageEncoding=UTF-8%> <%@ taglib prefix=c uri=http://java.sun.com/jsp/jstl/core%>
I have created Spring 3.0 application where after Login user get displayed jsp page
I have problem with show or hide form in Window Form Application. I start
I have problem with UIWebView delay when the load image from url. In my
Have problem while getting data from Memcached on .NET MVC solution. I have this
I have followed reply from BalusC to resolve my problem How do I make
I have problem with I18N in JSP, specifically, with forms. When I enter some

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.