File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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: 16065
    
  21

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.


<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


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".


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet filters and static content