简体   繁体   English

JSTL arraylist。 值是空的

[英]JSTL arraylist. Value is empty

i was searching for the same problem as mine, but i didn't find anything. 我在寻找与我的问题相同的问题,但没有找到任何东西。 This is my problem: 这是我的问题:

I have ArrayList which includes beans. 我有包括豆的ArrayList。 My beans is class 'Row'. 我的豆类是“行”类。 There are setters and getters. 有二传手和吸气剂。

This is method from Database class: 这是Database类的方法:

public ArrayList<Row> getDatalist() {
    datalist = new ArrayList<Row>();
    try {
        String query = "SELECT * FROM ...";
        ResultSet r = s.executeQuery(query);
        while(r.next()) {
            Row row = new Row();
            row.setLocation(r.getString(4));
            row.setVolume(r.getInt(3));
            row.setTime(r.getTime(5));
            row.setDate(r.getDate(5));
            datalist.add(row);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return datalist;
}

My servlet: 我的servlet:

    ArrayList<Row> rows = db.getDatalist();
    request.setAttribute("rows", rows);
    request.getRequestDispatcher("/main.jsp").forward(request,response);

And at least 'main.jsp': 至少是“ main.jsp”:

<c:forEach var="row" items="${rows}">
      <c:out value="${row.location}"></c:out>
</c:forEach>

The problem is that ${row.location} is empty. 问题是$ {row.location}为空。 My page source: 我的页面来源:

<c:forEach var="row" items="[webservice.model.Row@1e41769, webservice.model.Row@1bd0815, webservice.model.Row@15dd716, webservice.model.Row@1d40d08]">

      <c:out value=""></c:out>

</c:forEach>

Any idea? 任何想法? Thanks a lot. 非常感谢。

Well, your page source indicates the problem clearly: the c tags aren't interpreted by the container. 好吧,您的页面源代码清楚地表明了问题所在:容器未解释c标签。 This means that you forgot to declare the c taglib at the top of the JSP: 这意味着您忘了在JSP的顶部声明c taglib:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

be sure you have set this: 请确保您已设置:

<%@ page isELEnabled ="true"%>

to make el expression enable。 使el表达成为可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM