tags:

views:

1094

answers:

3

I have a JSP page running on Tomcat 5.5. I have the following code:

 <c:forEach var="i" begin="1" end="10" step="1">
  <c:out value="${i}" />
  <br />
</c:forEach>

The output I am getting is:

${i} 
${i} 
${i} 
${i} 
${i} 
${i} 
${i} 
${i} 
${i} 
${i}

I cant work out why the forEach loop is working but the output is not working. Any help any one could give would be great.

+5  A: 

I know it's supposed to be on by default, but I run across pages now and again (or even the same page that changes behavior) where the EL processing doesn't happen. Adding the following to the top of any such pages should resolve the issue:

<%@ page isELIgnored="false" %>

I add it to every page because it doesn't hurt, and I still don't know the root cause that occasionally causes a page to stop interpreting the EL expressions.

RHSeeger
On Tomcat 5.5, there are (only?) two possible reasons: invalid schema in web.xml, or el-ignored config option.
Peter Štibraný
I (and others) have had a single page working fine and, after changing something on the page (ie, adding some html), it just stops evaluating the EL expressions. The only explanation I can come up with is a bug in Tomcat somewhere, but it's not worth digging too deep into since enabling it manually (via the code above) resolves the problem.
RHSeeger
A: 

See my answer at http://stackoverflow.com/questions/472500/javascript-string-replace-str-works-weirdly-in-jsp-file/472573#472573 for possible reasons.

Longer answer: ${i} is expression in so called 'Expression Language'. Sometimes, Expression Language can be disabled. See above answer for potential reasons, and ways how to enable it.

Peter Štibraný
A: 

Use tomcat6. It doesn't requires any configuration for EL in web.xml.

Maheshkumar.P
Tomcat 5.5 also doesn't require any configuration for EL in web.xml. Tomcat 5.0 also doesn't. If you have had a problem with it, it lies somewhere else.
BalusC