1

I am using Struts1 and JSP. I can access the form property using the <bean:write> tag but I can't do it with the JSTL. Why not? My form is a DynaActionForm.

This statement works:

<bean:write name="myForm" property="origin"/>

This does not work, displays ${myForm.map.origin} plain vanilla:

<c:out value="${myForm.map.origin}"/>

This does not work either, displays ${myForm.origin} plain vanilla:

<c:out value="${myForm.origin}"/>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Susie
  • 5,038
  • 10
  • 53
  • 74
  • It's a legacy system and I am doing some enhancements. I guess they've always used struts1 and they don't want to change it to other framework from fear of breaking the system. – Susie Sep 13 '12 at 17:58
  • Tried it with just "origin" and it doesn't work. It prints ${origin} – Susie Sep 13 '12 at 18:54
  • 1
    I'm not sure why you tagged this question with `[javascript]`, I've removed it, but I just wanted to assure that Java/JSP and JavaScript have **absolutely nothing** to do with each other expect of the 1st 4 characters in the language name. Check the Wikipedia entries about both languages to learn about the strict difference. – BalusC Sep 13 '12 at 19:18

1 Answers1

4

That can happen if there's somewhere a Servlet/JSP, JSTL and/or web.xml version mismatch. During Servlet 2.3/JSP 1.2, EL was part of JSTL 1.0. During Servlet 2.4/JSP 2.0, EL was moved from JSTL to JSP and JSTL 1.1 shipped without EL. The web.xml version declaration dictates the Servlet/JSP version currently used and must be supported by the target container.

So, if you're using JSTL 1.0 on Servlet 2.4/JSP 2.0, or are using JSTL 1.1 on Servlet 2.3/JSP 1.2, then you will face exactly this problem. Also, if you're using JSTL 1.1 on Servlet 2.4/JSP 2.0, but the web.xml is declared conform Servlet 2.3 (or doesn't contain any version declaraion), then you will also face exactly this problem.

All is explained in our JSTL wiki page. You can also find download links to the right JSTL versions and examples of the right version-specific web.xml declarations in there.

Another possible cause is that you've a <%@page isElIgnored="true"%> declaration in top of the JSP or <jsp-config><el-ignored>true</el-ignored></jsp-config> in web.xml, but that's a too obvious cause to be overlooked.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • You are right about your first assumption about ${} being interpreted as plain text.I checked the version of my servlet using servletContext.getMajorVersion() and servletContext.getMinorVersion and I got 2 and 5 respectively. Does it mean I am using servlet 2.5? If that's the case then the problem is something else? – Susie Sep 13 '12 at 20:00
  • In this web application, there are other pages where they have used jstl and it has worked. It's only this particular jsp page that I am working with that has the problem. In my web.xml file, there is no mention of any version. – Susie Sep 13 '12 at 20:25
  • I finally solved it. You asked me if I had this statement in my jsp <%@page isElIgnored="true"%> . I didn't. I added this statement to my jsp but changed the true value to false and it worked. Would you happen to know whay that would happen? – Susie Sep 13 '12 at 21:14
  • 1
    Apparently it's globally configured in `web.xml` as `true`. – BalusC Sep 13 '12 at 22:35