• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL expression ${pageContext.request}

 
Colin Shine
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The EL expression returns a , not a .

This is a problem for me, because I want to prepend each 'src' attribute of my image tags with the application context path, i.e.

<img src="${pageContext.request.contextPath}/images/myimage.gif" />

There is no getContextPath() in ! Is there a way around this without some ugly hack like placing the context path as a context init param, so it's accessible through EL like: :roll:
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<img src="${pageContext.request.contextPath}/images/myimage.gif" />

Works for me.
What container are you using?
 
Colin Shine
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

Thanks for the quick reply! I'm using Tomcat 5.5.12.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried with 5.5.9 and
Context Path: ${pageContext.request.contextPath}
printed
Context Path: /SimpleServlet
 
Colin Shine
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I've got it to work!

The problem was I was using these images on my login page, and since they were under a secure directory, Tomcat wasn't serving them until I was logged in.

When it wasn't working, I checked the spec and jumped to the wrong conclusion... :roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic