2014-11-03 68 views
0

我想在我的jsp中使用jstl迭代一個對象列表,但是當我試圖訪問一個參數時它返回參數名稱,這裏'destination'代替實際價值。我究竟做錯了什麼?如何使用jsp迭代對象列表

這裏是我的jsp的一部分:

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

這裏是我的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); 
} 

的旅程對象包含:

public class Journey { 

    private String destination; 

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

    public String getDestination() { 
     return destination; 
    } 
} 

回答

0

試試這個:

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

做過這份工作,謝謝! – Yonnaled 2014-11-03 23:48:43

+0

沒問題,我回到了同一個問題... – 2014-11-03 23:51:55