问题
I have a simple controller which has a method
@RequestMapping(value = "/products")
public ModelAndView showProducts(){
ModelAndView mv = new ModelAndView("products");
mv.addObject("products", productDAO.getAllProducts());
return mv;
and then I have my products.jsp page with jstl included
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title></title>
</head>
<body>
Hello from products page.<br/>
<c:forEach var="prod" items="${products}">
${prod.price}
${prod.id}
</c:forEach>
</body>
</html>
The problem is that I see the result in the browser as ${prod.id} string and not the actual ID of the product I've set up. Has anyone encountered this problem ?
回答1:
EDIT:
The problem was with the web.xml - I was using a default maven-webapp archetype and the web.xml had this
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
So I just removed it and JSTL started working.
来源:https://stackoverflow.com/questions/29905584/jstl-cforeach-printing