Created a new Spring MVC project using MAven and Im having a problem where the modelAttributes are not getting substituted on the jsp page. For eg.,
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html" %>
Hello Worlds ${location} is ${weathers}
<c:out value="${location}"/>
displays
Hello Worlds ${location} is ${weathers}
${location}
instead of
Hello Worlds Omaha is Cold
Omaha
I'm guessing I'm missing a jar, I have the following in the mvn dependency list :
<dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-servlet_2.4_spec</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring<开发者_运维百科/artifactId> <version>2.0.7</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>2.5.5</version> </dependency>
I'm quoting from an answer I provided before to the problem of EL not working:
With other words, the EL expression doesn't get evaluated? That can have one or more of the following causes:
- Application server in question doesn't support JSP 2.0.
- The
web.xml
is not declared as Servlet 2.4 or higher.- The
@page
is configured withisELIgnored=true
.- The web.xml is configured with
<el-ignored>true</el-ignored>
in<jsp-config>
.
In your particular case, 1) can be scratched. 3) and 4) are too obvious to be overseen, so that can likely be scratched as well. Left behind point 2). Your web.xml
is apparently declared with an older version. Ensure that your web.xml
is declared as at least Servlet 2.4:
<web-app
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<!-- Here you go. -->
</web-app>
I suppose your servlet container is using JSP pre-2.0, where EL is ignored by default. Check what has been bundled with it.
Anyway, you have to specify the following:
<%@ page isELIgnored="false" %>
精彩评论