jsp页面没有在花括号内显示变量的值,只显示变量名



我正在学习springmvc并使用jsp作为我的视图层,但我对jsp页面有问题当我在像这样的模型中放入一个属性时

@RequestMapping
public String sayHello(ModelMap model)
{
model.addAttribute("message","welcome to 3-IDIOTS web store");
return "hello";
}

然后在jsp页面中hello.jsp我试着像一样使用它

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
<title>Title</title>
</head>
<h2>${message}</h2>
<body>
</body>
</html>

然后开始运行tomcat并运行应用程序这就是当我运行tomcat 时会发生的情况

注意:我知道我可以使用以下代码来解决它

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String message =(String) request.getAttribute("message");
%>
<html>
<head>
<title>Title</title>
</head>
<h2><%=message%></h2>
<body>
</body>
</html>

但我想知道为什么使用${meassage}的代码不起作用

此语法为el(表达式语言(必须显式启用。

在jsp中添加此参数isELIgnored=false

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="UTF-8" isELIgnored="false" %>

或者将其添加到web.xml 中

<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
</jsp-property-group>
</jsp-config>

最新更新