【发布时间】:2014-03-26 18:45:54
【问题描述】:
我是 Spring 框架和使用 jstl 的新手。我在 jsp 文件上显示我的数据时遇到问题。这是我的代码
控制器
@RequestMapping(method = RequestMethod.GET, value = "/test")
public ModelAndView getTest(HttpServletRequest request) {
List<Place> places = PlacesService.search(types, 48.137048, 11.57538599, 10000);
for(Place place:places){
System.out.println("Name: " + place.getName());
System.out.println("Rating: " + place.getRating());
System.out.println("Categories: " + place.getTypes());
counter++;
}
ModelAndView model = new ModelAndView("test");
model.addObject("places", places);
return model;
}
在我的 test.jsp 中
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
Hello World!
<c:forEach items="${places}" var="place">
<c:out value="${place.name}"/>
<c:out value="${place.rating}"/>
<c:out value="${place.types}"/>
</c:forEach>
<c:forEach begin="6" end="15" var="val">
<c:out value="${val}"/>
</c:forEach>
</body>
</html>
对于两个 for 循环,我都打印了 ${place.name}、${place.rating}、${place.types} 和 ${val}。但是System.print.out() 给了我想要的值。
我做错了什么?
【问题讨论】:
-
您使用的是什么 Servlet 容器?哪个版本?
-
对不起,我不知道它是一个简单的 maven 项目
-
你在使用Tomcat吗?哪个版本?
标签: java jsp spring-mvc jstl