JSTL c:out不显示变量的值 [英] JSTL c:out not showing the variable's value
问题描述
我正在按照关于春天的教程应该在控制器中设置一个变量,以便在呈现请求的jsp中进行打印.代码如下:
I'm following a tutorial about spring and I'm supposed to set a variable in a controller in order to be printed within the jsp rendering the request. The code is as follows:
@Controller
public class HelloController {
@RequestMapping(value="/hello.htm")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String now = (new Date()).toString();
return new ModelAndView("WEB-INF/views/hello.jsp", "now", now);
}
}
然后,hello.jsp代码如下:
Then, the hello.jsp code is as follows:
<%@ page session="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<body>
<p>Greetings, it is now <c:out value="${now}" /></p>
</body>
</html>
我希望得到一个显示以下内容的html:
I am expected to get an html showing this:
Greetings, it is now Mon Fri Dec 06 00:39:35 CET 2013
但是我得到的只是:
Greetings, it is now ${now}
我已经对所有内容进行了两次检查(甚至更多!),但是所有内容似乎都与教程中所说的一样,但是我希望一定缺少某些内容...
I've checked everything twice (or even more!) but everything seems to be as the tutorial says but there must be something missing, I hope...
我的代码怎么了?
推荐答案
这是一个 E xpression L 语言问题.您的${}
尚未解决.发生这种情况可能有多种原因.一种,也是最有可能的是,您的web.xml声明了Servlet 2.3及更低版本.您必须指定2.4+.现在,显然,您的Servlet容器还必须支持该更高版本.
This is an E xpression L anguage issue. Your ${}
is not being resolved. This can happen for a number of reasons. One, and the most likely, is that your web.xml is declaring Servlet 2.3 and under. You'll have to specify 2.4+. Now, obviously, your Servlet container must also support that higher version.
这篇关于JSTL c:out不显示变量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!