facebook

relational filepaths

  1. MyEclipse IDE
  2.  > 
  3. Comments
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #211719 Reply

    dom
    Member

    I’m using Tomcat 5 and when my jsp uses a relational filepath to look for an image source file that begins with a ‘/’ the image is not found because it looks for a folder in the Tomcat root directory rather than the project’s own root directory which is in the Tomcat one. So for example ‘images/animage.gif’ is ok but ‘/images/animage.gif’ is not. Any help with overcoming this querk would be appreciated.

    #211723 Reply

    Riyad Kalla
    Member

    dom,
    I’m moving this to Random Thoughts because this isn’t related to ME but is instead a problem that any web application developer must overcome when dealing with web context paths.

    Now as far as getting around this problem, you can try and use the <html:base /> tag from Struts to set a base for each page, or what I prefer is the html:rewrite tag and/or the page argument which will do a application-relative lookup for a resource.

    If you aren’t using Struts and just want a vanilla way to do this, from your JSP page you can get the servletContext and determine the path of this base servlet that was called, and then prepend that to your image path:

    <img src=”<%= basePath %>/images/header.gif”>

    or something like that.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: relational filepaths

You must be logged in to post in the forum log in