【问题标题】:JSP Print data from an array listJSP 从数组列表中打印数据
【发布时间】:2015-10-29 18:55:50
【问题描述】:

我有一个带有Flight 的 POJO,其中我只有一些私有类变量、getter 和 setther,并且我的 servlet 中有以下代码:

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

还有下面的jsp页面

<%@ 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>

问题是它没有按我预期的方式工作。它在表中打印值${...}。我该如何解决这个问题?

【问题讨论】:

    标签: java jsp printing


    【解决方案1】:

    我觉得您没有正确配置 jstl,因此 for 循环的行为方式不正常。尝试如下所示的简单 forEach 以查看您的设置是否有效。

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

    另见

    【讨论】:

      【解决方案2】:

      我已经添加了

      <%@ page isELIgnored="false" %>
      

      现在可以了

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-04
        • 1970-01-01
        • 2022-01-14
        • 2012-03-05
        相关资源
        最近更新 更多