Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

serve static HTML from app context rather than ROOT

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JSP application (myapp) deployed successfully in Tomcat 5.5.12 with J2SDK1.5 VM. It successfully locates my compiled .class files and jsp's under my webapps/myapp application context directory, under WEB-INF and so forth.

My problem involves the static HTML and .gif files referenced in the jsp's.
Tomcat insists on finding them only under webapps/ROOT, rather than webapps/myapp . I have tried using relative and absolute URLs for the static HTMLs and GIFs. Tomcat only understands the relative URL (which is relative to the basepath of the application). Tomcat finds these HTML & GIF files when I copy them under webapps/ROOT instead of the webapps/myapp. I have verified that this is not a start-up, refresh, or cache problem. Tomcat instantly serves the referenced files if they are moved to webapps/ROOT when I resubmit the jsp application, and instantly sees that they are gone if I delete them from webapps/ROOT . Tomcat never sees the files when they are under webapps/myapp (which is where they are supposed to be).

Any suggestions?
[ January 23, 2006: Message edited by: johnfake temp ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
johnfake temp
Welcome to JavaRanch!

We're pleased to have you here with us in the Tomcat forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you referencing the images?
What is the syntax of your <img .. /> tags?
 
john findler
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
How are you referencing the images?
What is the syntax of your <img .. /> tags?



For static html references, this serves the file if its in webapps/ROOT:
See <a href="../Rules.html">Rules</a> <br>

For Gifs, for example, this serves the file if its in webapps/ROOT:

<body background="../libback.gif">


I have tried all combinations of
href="./Rules.html" <br>
href="../images/Rules.html"
href="<%=basePath%>Rules.html" (no extra "/" between the > and Rules)

and I have copied these html and gif files to everywhere under webapps/myapp:
...webapps/myapp
...webapps/myapp/WEB-INF
...webapps/myapp/images
...webapps/myapp/WEB-INF/classes

and in doing so, I have tried full shutdown of Tomcat, browser, and host,
and redeploy. Nothing makes Tomcat look in myapp for static files. It insists on looking in its ROOT for my static pages, even though it finds my jsp's references to jsp and classes under webapps/myapp just fine

Any suggestions now? (Thanks)

[ January 23, 2006: Message edited by: john findler ]
[ January 23, 2006: Message edited by: john findler ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I see it.

First the parts of the URL:


If you refer to an image with a relative url that begins with a forward slash, the browser is going to build the url starting at the end of the domain.

For example, if you have a JSP in the root of the myApps webapp and you use:
<img src="/images/myImage.gif">
The browser will look in:
http://localhost/images/myImage.gif
Note your contextPath is missing.

try:
<img src="${pageContext.request.contextPath}/images/myImage.gif" />
 
john findler
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
... try:
<img src="${pageContext.request.contextPath}/images/myImage.gif" />



I agree with all of your facts. But Tomcat is not cooperating.

Here's some more detail - maybe you can help me find the problem:

1. I TRIED YOUR GOOD SUGGESTION

My href="<%=basePath%>Rules.html"
and img src="<%=basePath%>images/libback.gif"> (note that basePath has an ending slash in it)

have the identical effect as when I change to the syntax based on your suggestion:

... ="${pageContext.request.contextPath}/images/myImage.gif"

I verified that the browser's Properties on these links yields the correct absolute paths.

The resulting absolute URLs for my GIF and html become these according to the browser:
http://localhost/myapp/Rules.html
and
http://localhost/myapp/images/libback.gif
respectively.
These seem correct, but Tomcat does not want to serve them up.

But Tomcat does not treat these absolute URLs as expected.
The GIF displays as a broken [x] symbol on my jsp's page,
and if I click the html link, the browser just redisplays my jsp page.
It doesn't even given me a page not found or complain.


2. I TRIED ENTERING THE URLS DIRECTLY

I have even tried entering these absolute URLs in the browser address field directly.
Tomcat just does not revise the page, and doesn't complain.

As a sanity check, when I enter an absolute URL to the these same files which I copied again to webapps/ROOT, and webapps/ROOT/images,
Tomcat displays them fine. (e.g. http://localhost/Rules.html works fine). So there isn't anything wrong with the files themselves or the ability to serve them via an absolute URL to ROOT on purpose.


3. MAYBE A CLUE: TOMCAT DISPLAYS MY jsp page WHEN IT DOESN't FIND INTENDED FILES

I am wondering why Tomcat doesn't complain when it can't find the files instead of just redisplaying my jsp page.

It's as though Tomcat thinks the URL is addressing a directory and then displaying the default welcome page for .html or .gif .
But this can't be: I've checked all of the web.xml files in my Tomcat installation, and none of them
mention my application .jsp as the default welcome page or anything.

Thanks again in advance for your kind expert help

[ January 23, 2006: Message edited by: john findler ]
[ January 23, 2006: Message edited by: john findler ]
 
john findler
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GOT IT !!! I'll describe the solution tomorrow. simple.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me guess:
You have a url-mapping that looks something like
<url-mapping>/*</urlmapping>
or
<url-mapping>*</urlmapping>
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic