JSTL c:forEach打印$ {} [英] JSTL c:forEach printing ${}

查看:82
本文介绍了JSTL c:forEach打印$ {}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的控制器,其中有一个方法

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;

然后我有包含jstl的product.jsp页面

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>

问题是我在浏览器中看到的结果是$ {prod.id}字符串,而不是我设置的产品的实际ID.有人遇到过这个问题吗?

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 ?

推荐答案

问题出在web.xml上-我使用的是默认的maven-webapp原型,而web.xml具有此

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" >

所以我刚刚将其删除,JSTL开始工作.

So I just removed it and JSTL started working.

这篇关于JSTL c:forEach打印$ {}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆