0 Replies Latest reply: Nov 29, 2012 4:11 AM by 851855 RSS

    Servlet filter on 404 error page

    851855
      When a request results in 404 error, the filter code after chain.doFilter() is executed after calling/processing 404 servlet. Is this a bug?

      Example:
      I call /myapp/x/x/x which is not available.
      Code Flow in Weblogic:
      MyCOntroller.preFilter() --> MyCOntroller.chain.doFilter() --> VirtualLinkHandler servlet --> MyCOntroller.postFilter().

      Code Flow in Tomcat/Other servers:
      MyCOntroller.preFilter() --> MyCOntroller.chain.doFilter() --> MyCOntroller.postFilter() --> VirtualLinkHandler servlet


      MyController.java [Servlet Filter]:
      public void doFilter(ServletRequest req, ServletResponse resp,
      FilterChain chain) throws ServletException, IOException
      +{+
      preFilter();
      chain.doFilter(req, resp);
      postFilter();
      +}+

      web.xml::

      <filter>
      <filter-name>MyController</filter-name>
      <filter-class>com.web.env. MyController </filter-class>
      </filter>
      <filter-mapping>
      <filter-name> MyController </filter-name>
      <url-pattern>/*</url-pattern>
      <dispatcher>REQUEST</dispatcher>
      </filter-mapping>


      404 Page:
      <servlet>
           <servlet-name>VirtualLinkHandler</servlet-name>
           <servlet-class>com.web.virtuallink.VirtualLinkHandler</servlet-class>
      </servlet>
      <servlet-mapping>
           <servlet-name>VirtualLinkHandler</servlet-name>
           <url-pattern>/VirtualLinkHandler</url-pattern>
      </servlet-mapping>
      <error-page>
           <error-code>404</error-code>
           <location>/VirtualLinkHandler</location>
      </error-page>