• Post Reply Bookmark Topic Watch Topic
  • New Topic

Paths are not working after forwarding

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Consider the following web application structure :

My application use Struts and SiteMesh.
To use an image inside a JSP page, I wrote :

The problem arises when a Struts action forwards the request to JSP page, the images is not shown.
Any ideas how to solve this problem beside using ${pageContext.request.contextPath} ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When servlets are involved, the whole notion of "file location" goes out the window.

In the web app environment, it's best to not use page-relative references to resources (images, style sheets, scripts, etc).

Rather, use server-relative references.

For example (assumes JSP 2.0):

<img src="${pageContext.request.contextPath}/images/whatever.jpg"/>
[ July 14, 2006: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Todd:

Any ideas how to solve this problem beside using ${pageContext.request.contextPath} ?


What's wrong with that?
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with that?

The context will be shown in the generated source, is it good ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why wouldn't it be?

The context will part of the URL anyway.
It's dynamic so it will change if you change the context path.

I can't think of why that could possibly be a problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!