0

Environment:

  • Tomacat 8
  • Servlet 3.1
  • JSP 2.3
  • Java 1.7.0_79
  • Maven
  • Struts2

Why doesn't work EL in this JSP file?

el.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    ${5+3 }
    ${5+hola }
    <s:url action="registerInput" var="registerInputLink" />
    ${registerInputLink}
</body>
</html>

and what I see in the web page is:

${5+3 } ${5+hola }  ${registerInputLink} 

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
Joe
  • 7,749
  • 19
  • 60
  • 110
  • 1
    Maybe EL is ignored. Try to add in directive <%@ page isELIgnored="false" %> to your JSP. – Tony Vu Aug 04 '15 at 03:10
  • Yes, it is. But where is that ignored, in web.xml? or is it the default option? – Joe Aug 04 '15 at 06:59
  • In this version it shouldn't be deactivated per default. Maybe a small error sneaked in your web.xml. Could you post the web.xml. – user3584190 Aug 04 '15 at 07:31

1 Answers1

0

The problem seems to be with your web.xml. You have to add some namespaces to the web-app tag

web.xml header for servlet 3.1

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
        http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1">
    <!-- Config here -->

You can find the correct namespaces for your Tomcat instance in the example apps that come with a Tomcat install.

Joe
  • 7,749
  • 19
  • 60
  • 110
underdog
  • 4,447
  • 9
  • 44
  • 89