The moose likes Servlets and the fly likes Servlet containers and static resources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet containers and static resources " Watch "Servlet containers and static resources " New topic

Servlet containers and static resources

Alexey Gor

Joined: Jul 13, 2004
Posts: 27

I cannot find much regarding specification for serving static resoruces (images, etc) from Servlet Containers.
2.4 Servlet spec implies that this is done via "Image conversion filters" (page 50)...

it also mentions this:

<filter-name>Image Filter</filter-name>

Does this mean all static content is served using a filter? I got a blank installation of Tomcat and could not find anything image-related other than:

what am I missing? I decided to post this into Servlet forum because it seems to be a matter of standards rather than Tomcat... Thanks!
Jon Emerson

Joined: Feb 19, 2006
Posts: 5
If you put your images right inside your web application just like you would put a JSP, web clients can simply access them directly without any filters or mapped servlets.

For example, if your webapp is named "test.war", and you put "test.gif" in the root directory of the WAR, the image can be retrieved directly from http://localhost:8080/test/test.gif.

Jon Emerson<br /> <a href="http://www.jonemerson.net" target="_blank" rel="nofollow">http://www.jonemerson.net</A>
Alexey Gor

Joined: Jul 13, 2004
Posts: 27
Thanks for your response, but I want to actually understand how this works. i.e. how does Servlet Spec specify static content to be handleled and how it fits within the whole scheme of mapping servlets to URIs.

The part I'm most curious about is this. If static content is served by a servlet/filter, then why cannot i find the mapping for it? If static content is served by some other means, why cannot i find that in the spec?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Tomcat handles this with the DefaultServlet.
The mapping for it is in the web.xml file in tomcat/conf.

I'm most other containers deal with this in a similar way.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link: http://aspose.com/file-tools
subject: Servlet containers and static resources