JSTL c:forEach printing ${}

一世执手 提交于 2019-12-25 00:37:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!