Class MyTomcatFilter

  • All Implemented Interfaces:
    javax.servlet.Filter

    public class MyTomcatFilter
    extends Object
    implements javax.servlet.Filter
    A really basic filter. Any path that starts with a "/pages" or a "/static" is intercepted and passed to the default java servlet that Tomcat runs. Your static content goes into the directory named static and your other content is served from the directory called pages. This fixes a feature of Tomcat 6 that allowed the default servlet to serve up static content from the top-level directory including possibly sensitive information. Tomcat 7 prohibits this, so we have to route static requests ourselves.

    Note that this (or some other similar filter) must be specified in your deployment descriptor (web.xml file) in order to serve up static pages.

    Created by Jeff Gaynor
    on 3/27/12 at 11:11 AM

    • Constructor Detail

      • MyTomcatFilter

        public MyTomcatFilter()
    • Method Detail

      • destroy

        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Filter
      • init

        public void init​(javax.servlet.FilterConfig filterConfig)
                  throws javax.servlet.ServletException
        Specified by:
        init in interface javax.servlet.Filter
        Throws:
        javax.servlet.ServletException
      • doFilter

        public void doFilter​(javax.servlet.ServletRequest request,
                             javax.servlet.ServletResponse response,
                             javax.servlet.FilterChain chain)
                      throws IOException,
                             javax.servlet.ServletException
        Specified by:
        doFilter in interface javax.servlet.Filter
        Throws:
        IOException
        javax.servlet.ServletException