tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pascal Guy <>
Subject Re: Resource configuration problems on servlets (images, css, javascript)
Date Tue, 28 Nov 2006 21:28:39 GMT

i have tried the absolute path

    <img border="0" src="/images/topImage.gif" width="300" height="15">

which renders to

    http://localhost:8080/images/topImage.gif       (which i know is not 
the good path)

but in the jsp we access the resource like this

    <img border="0" src="<%=request.getContextPath() + 
"/images/topImage.gif"%>" width="300" height="15">

which renders to

    http://localhost:8080/TEST/images/topImage.gif    (where TEST is my 

this worked fine for my partner on his sample controller servlet but did 
not have any server side code except the jsp
also when i look at the deployed application in Eclipse it gives me this 


so the path is good (i think) when i look at the properties of the 
images on the html page

you said all the resources should make a request to the server but what 
i can't understand is why is it being caught and treated by my servlet

that's why i assumed there was some configuration problem so these 
request would be treated by a default servlet of some sort and not my 
which is configured to have event types for every request and treats 
these requests for resources as "unknown events"

my lack of knowledge in servlets is probably misleading me here


Kristian Rink wrote:
> Hi;
> Pascal Guy schrieb:
>> The problem comes when we integrate to post the request to my controller
>> The controller works fine but the resources are not working (css, images
>> and javascript)
> I am not sure to understand your problem right, but:
>>    <servlet-mapping>
>>        <servlet-name>controller</servlet-name>
>>        <url-pattern>/controller</url-pattern>
>>    </servlet-mapping>
> [...]
>> Do i need to map the resource types to something so it bypasses my
>> servlet (and not be treated as a request)
> There _will_ be a request for each and every static component (i.e.
> image, css, js file, whatever) to be loaded from the server - but
> indeed, you shouldn't have your controller taking care of that.
> How are you referring to images and js from within your code? You should
> be sure to use absolute URLS (i.e. "/images/logo.png" instead of
> "images/logo.png"), otherwise you might end up with your server
> searching for the content in a place where it's not supposed to be found
>  (i.e. "/<servlet-context>/controller/images/logo.png"). If you keep
> that in mind, chances are you won't have to do much configuration work
> in your web.xml but simply ensure that folders containing static things
> are somewhere out of the way of your servlet mappings.
> Hope this helps, good luck to you!
> Cheers,
> Kris
> ---------------------------------------------------------------------
> To start a new topic, e-mail:
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message