• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL not getting translated in JSP page

 
Anjali Krishnan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the EL in my JSP pages are not getting tranlated. I am trying executing the JSP using Tomcat 5.0. The EL example is from HFSJ book page 376. The following are my code snippets.

My web.xml has the following dtd definition
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_4.dtd">

and in my servlet
java.util.Map musicMap = new java.util.HashMap();
musicMap.put("Ambient", "Zero 7");
musicMap.put("Surf", "Tahiti 80");
musicMap.put("TJ", "BT");
request.setAttribute("musicMap", musicMap);

the JSP code

The EL is
${musicMap("Ambient")}

The result I get is when I run the JSP locally is
The EL is ${musicMap("Ambient")}


Any ideas why the EL is not getting translated.
Any help appreciated.
Thanks,
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you installed the latest version of tomcat?

Should it not be : ${musicMap["Ambient"]} (Square brackets?)

Please recheck.

Regards,
Shivani
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My web.xml has the following dtd definition
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_4.dtd">
Why do you reference the PUBLIC URI as first "DTD Web Application 2.3" but then refer to the web-app_2_4.dtd file? You should change it to "DTD Web Application 2.4".

EL is only enabled by default when using a JSP 2.0 compliant container (make sure you're using Tomcat 5.x or later) and a Deployment Descriptor version 2.4 or higher. I would recommend, however, using the alternative XML Schema declaration for v2.4 of the DD. This might solve your problems. Alternatively, add this to your JSP page:This will force your container (if it is JSP 2.0 compliant) to translate the EL. This is not recommended on a large scale, and if you can find an alternative, more widely applicable, solution that's preferable.
 
Anjali Krishnan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your replies. As per the suggestions, I made the following change to the web.xml file
<?xml version="1.0" encoding="ISO-8859-1"?>
<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">

and in the JSP I changed to '['
The Music EL is ${musicMap["Ambient"]}

The rest of the EL in my JSP get translated eg ${pageContext.request.method} but not the musicMap EL.
I get a blank
Thanks,
 
Martyn Clark
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anjali,
Looking at your code i am just wondering whether you have used the requestDispacher to forward you request response objects. The reason i ask is because you say that other EL is working fine and i can not see a problem with ${musicMap["Ambient"]} can you paste your full servlet code?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic