简体   繁体   English

如何使用JSP迭代对象列表

[英]How to iterate a list of objects using jsp

I am trying to iterate a list of objects in my jsp using jstl, but when I'm trying to access a parameter it returns the parameter name, here 'destination' instead of the actual value. 我试图使用jstl迭代jsp中的对象列表,但是当我尝试访问参数时,它返回参数名称,这里是“目标”而不是实际值。 What am I doing wrong? 我究竟做错了什么?

Here is a part of my jsp: 这是我的jsp的一部分:

<c:forEach items="${journeys}" var="journey">
    ${journey.destination}
</c:forEach>

Here is my servlet: 这是我的servlet:

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
    SearchForm form = new SearchForm();
    List<Journey> journeys = form.searchJourney( request );
    request.setAttribute( "journeys", journeys );
    this.getServletContext().getRequestDispatcher( VIEW ).forward( request, response );
}

And the journey object is containing: 旅程对象包含:

public class Journey {

    private String destination;

    public void setDestination(String destination) {
        this.departure = destination;
    }

    public String getDestination() {
        return destination;
    }
}

尝试这个 :

<c:out value="${journey.destination}"/>

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

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