JSP EL ${stuff} syntax not working
Asked Answered
N

1

8

I have two problems. The first one is that I'm using JSP and that I can't solve. The second one is that I'm getting an odd behavior.

When I put this in the doGet() method of my servlet

req.setAttribute("test", "SARASA");
req.getRequestDispatcher("WEB-INF/main.jsp").forward(req, resp);

And this in "WEB-INF/main.jsp":

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%= request.getAttribute("test") %>
<c:out value="${test}"/>

The output is:

SARASA ${test}

I don't know what I'm doing wrong... what can be the reason for this?


Update: I solved it adding

<%@ page isELIgnored="false" %>

In each JSP where I needed it. Oddly, I didn't needed that in another project using some very similar web.xml and pom.xml files (I'm using maven).

Nolannolana answered 10/9, 2011 at 21:29 Comment(2)
test is the name for the attribute I was setting (see the servlet), mapped to a string that says "SARASA"Nolannolana
See also bottom of our JSTL wiki page: stackoverflow.com/tags/jstl/infoOvereager
C
11

Your web.xml is probably referencing the Servlet 2.3 spec, in which isELIgnored is set to true by default. If you reference the Servlet 2.4 spec instead, isELIgnored will be set to false by default.

If you want to reference the Servlet 2.4 spec, your web.xml header should look something like this:

<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">
Condemnation answered 10/9, 2011 at 21:40 Comment(1)
Thank you. The problem was that there was no reference to anything... I didn't saw it because it was in the doctype!!! (I usually ignore that) <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "java.sun.com/dtd/web-app_2_3.dtd" >Nolannolana

© 2022 - 2024 — McMap. All rights reserved.