Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet filters and static content

 
Andy Wilson
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic