tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Morgan, Russel" <>
Subject RE: Help Linking Static Content In a WebApp before and after (6.0.30.x)
Date Wed, 06 Jun 2012 20:48:59 GMT
I found a fix :)

Thanks again for all the replies, the thought that if a resource wasn't mapped it would drop
to the default servlet got me thinking.

I did some looking and it was actually my spring dispatcher picking up /* and causing calls
to static resources to fail as the dispatcher picked them up.



Sure enough if I commented that out, then my static paths worked great.

Obviously this killed my application though, as the dispatcher wasn't handling requests. 
I did a bunch of searching around and reading on Spring and found that adding the following
entries to my spring config allowed me to control routing on the 5 versions of tomcat I tested

What I added to my appicationContext.xml

   Then to go with that the following schema locations:

   <mvc:resources mapping="/resources/**" location="/"/>

(info on that last little gem, which still "feels" hacky)
16.14.6 mvc:default-servlet-handler

This tag allows for mapping the DispatcherServlet to "/" (thus overriding the mapping of the
container's default Servlet), while still allowing static resource requests to be handled
by the container's default Servlet. It configures a DefaultServletHttpRequestHandler with
a URL mapping of "/**" and the lowest priority relative to other URL mappings.

This handler will forward all requests to the default Servlet. Therefore it is important that
it remains last in the order of all other URL HandlerMappings. That will be the case if you
use <mvc:annotation-driven> or alternatively if you are setting up your own customized
HandlerMapping instance be sure to set its order property to a value lower than that of the
DefaultServletHttpRequestHandler, which is Integer.MAX_VALUE.

Thanks again everyone!

-----Original Message-----
From: Christopher Schultz [] 
Sent: Wednesday, June 06, 2012 6:30 AM
To: Tomcat Users List
Subject: Re: Help Linking Static Content In a WebApp before and after (6.0.30.x)

Hash: SHA1


On 6/6/12 8:45 AM, Morgan, Russel wrote:
> So if I bundle the default servlet with my application and then 
> configure it to run as a different named servlet, and map static 
> resources to it within the webapp that should work? (I will certainly 
> try that)
> Also, all "tricks" aside, what is the proper way to address static 
> assets deployed within a webapplication, if pathing them to the 
> default servlet is inappropriate?

What's wrong with letting the DefaultServlet continue to do its normal job by serving every
resource that isn't otherwise mapped?

> Forgive my ignorance but couldn't I just set this in my webapp xml 
> descriptor, and "rename" it, and then path to it?

Why bother? If /resources/css/gopublish.css isn't mapped explicitly, then the DefaultServlet
will look in your webapp's /resources/css/ directory for gopublish.css and serve the bytes
no problem.

> Perhaps the fact that the code is loaded by the webapp class loader 
> makes a difference , I am not sure. (just ruling out this
> possibility)

It does not matter.

I think I've gotten lost... what are you actually trying to accomplish, here? Do you have
a bunch of static content that is outside of the webapp's docBase that you want to serve from
within its URL space? Any possibility that you could upgrade to Tomcat 7 which has "aliases"
which can do this?

- -chris
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools -
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message