Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Paths in Tomcat standalone mode

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application under Tomcat. and my problem is that it does handle relative paths very well, but not the paths wrt the root-context.
say I am in root-context/files/f1.jsp
If i refer to /images/img1.gif here It cannot handle this request. Although img1.gif exists inside root-context/images/img1.gif
Regards,
c.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A reference to /images/img.gif is relative to the ROOT directory, not some web application context. Thats not a Tomcat problem.
I think that using "../images/img.gif" might be what you want - the .. says back up one directory from where the jsp lives.
Bill
[ December 25, 2002: Message edited by: William Brogden ]
 
Brusk Baran
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William,
I am aware of the ../ stuff.
I just wanted to know why /images/someImage.gif does not work!! why does it refer to $WEB-APPLN_SERVER/webapps/ROOT/ directory. I see no reason..
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first / refere to the root of the Web-Server - e.g. 'http://127.0.0.1/' - in your case '$WEB-APPLN_SERVER/webapps/ROOT/'
Rene
 
Bartender
Posts: 20847
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing to realize is that although they LOOK the same, a URL is NOT actually a directory path. In many cases, they do map, but not all (as for example the Apache Alias directive). In fact, some webservers secure themselves by NOT assuming that the filesystem tree will map node-for-node and thus requiring explicit URI/directory mappings.
Among the things that can cause confusion is if you map a web app to a complex context using a mechanism such as the Tomcat <context> directive and/or a context definition in an EAR's application.xml file.
For example (from an EAR's application.xml):

Let's say that the directory structure looks like this:

The canonical URL for the image1 file would be something like http://www.myserver.com:8080/wowser/images/image1.png
For a JSP at http://www.myserver.com:8080/wowser/index.jsp, the relative-to-root path for the image1 file would be "/images/image1.png" because the TOMCAT_ROOT/webapp/ directory would be implicit and the wowser/ would be part of the context root. Usually, of course, you'd just have "/" as the context root, so the image1 URL would be http://www.myserver.com:8080/images/image1.png
"../images/image1.png" would also work - in this case you're explicitly mapping relative to the referrer's context location rather than walking down from the context root.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!