File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Servlet filters and static content Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Servlet filters and static content" Watch "Servlet filters and static content" New topic

Servlet filters and static content

Andy Wilson
Ranch Hand

Joined: Jun 26, 2009
Posts: 32
I'm producing a filter that modifies the response text of JSP requests. However, I also want to modify included static files such as .css and .js
files. The filter works fine on the output from the JSP's, but doesn't on any .css and .js requests. I can see the .css files and .js files being processed, but the response text they work on is empty.

I'm thinking that the servlet engine doesn't handle static content, and this is why the response for static content is empty.
Is this the case? How are requests to static files served up in Tomcat 6?

Any comments appreciated.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

If you'll look in the TOMCAT_HOME/conf/web.xml file you'll see the answer.

<!-- ================== Built In Servlet Definitions ==================== -->

<!-- The default servlet for all web applications, that serves static -->
<!-- resources. It processes all requests that are not mapped to other -->
<!-- servlets with servlet mappings (defined either here or in your own -->
<!-- web.xml file. This servlet supports the following initialization -->
<!-- parameters (default values are in square brackets): -->

The actual default servlet itself is defined in the usual way.


If your modifications have anything to do with altering cache control headers, you should know that there are less intrusive ways, however.

And, of course, if you muck around with the DefaultServlet's internals, you'll be working outside the pale of the J2EE standard and the resulting WAR will not be "write once run anywhere".

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Servlet filters and static content
It's not a secret anymore!