Martin Rezyne
Martin Rezyne

Reputation: 445

JSP Print data from an array list

I have a POJO with Flight where I have only some private class variables and getters and setther and I have the following code in my servlet:

request.setAttribute("FLIGHT_LIST", flightList);
request.getRequestDispatcher("/user_panel.jsp").forward(request, response);

And the following jsp page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="entities.Flight"%>
<%@ page import="java.util.List"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h3>Hello im user</h3>
<div>
    <a href="login.jsp">Login</a> | <a href="/Airport/LogoutServlet">Logout</a>
    | <a href="/Airport/UserProfile">Profile</a>
</div>
<hr>
<div>
    <table style="width: 100%" border="1">
        <tr>
            <th>ID</th>
            <th>Number</th>
            <th>Type</th>
            <th>Departure City</th>
            <th>Departure Time</th>
            <th>Arrival City</th>
            <th>Arrival Time</th>
        </tr>
        <tr>
            <td>Eve</td>
            <td>Jackson</td>
            <td>94</td>
            <td>94</td>
            <td>94</td>
            <td>94</td>
            <td>94</td>
        </tr>
        <c:forEach var="element" items="${FLIGHT_LIST}">
            <tr>
                <td><c:out value="${element.idflight}" /></td>
                <td><c:out value="${element.number}" /></td>
                <td><c:out value="${element.type}" /></td>
                <td><c:out value="${element.departureCity}" /></td>
                <td><c:out value="${element.departureTime}" /></td>
                <td><c:out value="${element.arrivalCity}" /></td>
                <td><c:out value="${element.arrivalTime}" /></td>
            </tr>
        </c:forEach>
    </table>
</div>
<hr>
....
</body>
</html>

The problem is that it isn't working the way I expected to. It prints in the table the values ${...}. How can I fix this problem?

Upvotes: 0

Views: 529

Answers (2)

Martin Rezyne
Martin Rezyne

Reputation: 445

I have added

<%@ page isELIgnored="false" %>

and now it works

Upvotes: 0

RockAndRoll
RockAndRoll

Reputation: 2277

I feel you haven't configured jstl properly so the for loop isn't behaving the way it shud.Try a simple forEach like below to see whether your set up works or not.

<c:forEach var="i" begin="1" end="5">
   Item <c:out value="${i}"/><p>
</c:forEach>

See Also

Upvotes: 1

Related Questions