JSTL variables are not displayed in EL

JSTL variable values ​​are not displayed in EL. For example, this code:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="s" uri="http://www.springframework.org/tags" %> <html> <body> <c:forEach var="i" begin="1" end="5" > <c:out value="${i}" /> </c:forEach> </body> </html> 

the browser displays: ${i} ${i} ${i} ${i} ${i}

Or this one:

 <c:set var="someVar" value="Hello"/> <c:out value="${someVar}"/> 

browser displays: ${someVar}

I use Spring-MVC 3 and Maven to create a sample project, deploying it to Tomcat 7. In the context of Spring, I have a permissions configurator configured as follows:

 <bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value=" org.springframework.web.servlet.view.JstlView"></property> <property name="prefix" value="/WEB-INF/"></property> <property name="suffix" value=".jsp" /> </bean> 

The presented model variables processed by the Spring form are also not shown.

Mavens pom.xml has the following jstl dependencies:

 <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> <scope>runtime</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.1</version> <scope>provided</scope> </dependency> 

So, any suggestions to fix this?

+4
source share
1 answer

So, EL (those ${} things) are not running? This can happen when your servlet container is running in Servlet 2.3 / JSP 1.2 or lower while you are using JSTL 1.1 or later. During the transition from JSTL 1.0 to 1.1, the EL was moved from JSTL to JSP. It was JSP 2.0, which is part of Servlet 2.4. JSP 1.2 and older do not have an EL package. JSTL 1.1 and later are not affiliated with EL.

You need to make sure your root web.xml declaration matches at least Servlet 2.4. Since you are using JSP 2.1, which is part of Servlet 2.5, you seem to be targeting a Servlet 2.5 compatible container. So, make sure your root web.xml declaration matches Servlet 2.5:

 <?xml version="1.0" encoding="UTF-8"?> <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_5.xsd" version="2.5"> <!-- Config here. --> </web-app> 

Tomcat 7 is, however, a Servlet 3.0 compatible container. I would consider changing maven pom to declare Servlet 3.0 / JSP 2.2 so that you can take advantage of all the new features of Servlet 3.0.

See also:

+10
source

Source: https://habr.com/ru/post/1401078/


All Articles