jsp page is not displaying the value of variable inside curly brackets just display the variable name

Viewed 36

I am learning spring mvc and using jsp as my view layer but I have a problem with jsp page when I put a an attribute in model like that

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

        return "hello";
    }

then inside the jsp page hello.jsp I try to use it like that

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


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

</body>
</html>

then start to run tomcat and run the application I get this this is what happens when I run tomcat

note: I know that I can solve it using the following code

<%@ 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>

but I want to know why the code using ${meassage} is not working.

1 Answers

This syntax is el (expression language) must be explicit enabled.

In the jsp add this parameter isELIgnored=false

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

Or add this in the web.xml

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