This question already has an answer here:
- EL expressions not evaluated in JSP 2 answers
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.
For those interested, the equivalent XML syntax for JSP 2.0 is:
It's the header in web.xml that causes the problem
Below maven generated header stops EL from being eval'ed.
Using below header eval's the EL.
See my answer at Javascript String.replace(/\$/,str) works weirdly in jsp file 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.
I just had this same problem and spent forever trying to figure out what was wrong.
I've developed lots of web apps from scratch. Why suddenly was this one not cooperating?
One difference was this time I used the maven webapp archetype to generate the project structure. It created a web.xml file that looked like this:
Once I realized that as my problem, I was sure I had the answer. So I copied one of my 2.5 web.xml headers, rebuilt, and redeployed. No cigar. Couldn't believe that wasn't the problem. Cleaned the project, restarted tomcat. Nope.
RHSeeger's answer led me to try putting in the <%@ page isELIgnored="false" %>. That resolved the problem. But I still wanted to know why el started getting ignored to begin with.
I figured the el was being ignored because of something wrong with my web.xml, so I closely inspected it in comparison with another webapp's web.xml that I knew worked fine. No noticeable differences.
Then I removed the <%@ page isELIgnored="false" %> from my JSP, and redeployed, assuming the el would not be evaluated again, but much to my surprise, the el was evaluated fine!
Then, figuring it must be some sort of caching problem, I undid my changes to the web.xml to recreate the problem. I redeployed, but still the el was being evaluated correctly, even with the bad web.xml. Then I cleaned my entire project (I'm using an exploded deployment), blowing away the exploded directory and recreating it. I then restarted tomcat. Still, the el appeared to be getting evaluated correctly in spite of the bad web.xml.
Finally it dawned on me. I simply added a space to some place in the JSP, repackaged it, and refreshed the page. Bingo! Now the el was not getting evaluated.
So the problem was with the web.xml. It would further complicated by the fact that the JSPs weren't getting recompiled unless they had changed. Not sure if tomcat uses an MD5 sum to decide if the JSPs need to be recompiled or what. Another possibility is that I'm using tiles, which I know has a caching mechanism, but I wouldn't expect that to survive an tomcat restart.
Anyway, unless you modify your JSPs AFTER fixing the web.xml, all bets are off as to whether the EL will start working again. Hope this saves someone else a headache. I'm also interested if anyone can tell me whether it was tomcat not recompiling the JSPs or tiles caching the output of the JSP. I'm pretty sure it's the recompile, because at compile time is when the JSP should have to figure out what to do with the ${} el expressions, right? Tiles can't actually cache what gets substituted into the el expressions, otherwise all kinds of problems would arise.
From Controller:
In View:
Output:
had similar problem to Kevin, i used maven to get started with webapp but no joy with evaluating expressions in jsp - i had to remove DOCTYPE header - all is good now without playing with isELIgnored bit - maven generates web.xml which links to 2.3 which as Peter stated has EL disabled by default