5 Replies Latest reply on Jul 13, 2006 2:53 PM by adamw

    Filter and servlet mappings

    adamw

      Hello,
      I have a servlet mapped to /*:

      <servlet-mapping>
       <servlet-name>myServlet</servlet-name>
       <url-pattern>/*</url-pattern>
      </servlet-mapping>
      


      and a filter mapped to /something/*:
      <filter-mapping>
       <filter-name>myFilter</filter-name>
       <url-pattern>/something/*</url-pattern>
       <dispatcher>INCLUDE</dispatcher>
       <dispatcher>FORWARD</dispatcher>
      </filter-mapping>
      


      At some point in my servlet, I forward the request:
      response.setContentType("text/html");
      request.getRequestDispatcher("/something/sth2").forward(request, response);
      


      However, the filter doesn't get invoked. The request goes straight to the servlet. Why is that?

      --
      Cheers,
      Adam

        • 1. Re: Filter and servlet mappings
          j2ee_junkie

          Adam,

          That is the behavior defined by the servlet spec. If you want a filter on that resource to be invoked, then you need to use re-direct, not forward.

          cgriffith

          • 2. Re: Filter and servlet mappings
            adamw

            OK, thanks.

            --
            Adam

            • 3. Re: Filter and servlet mappings
              adamw

              Hello,
              I'm still wondering tho, why does it work if the servlet is mapped to a more specific path - like /xxx/* - then the forwards work as they should.

              --
              Cheers,
              Ada

              • 4. Re: Filter and servlet mappings
                adamw

                Hello,

                is there any way then to include a JSP page in a servlet, which is mapped to /*? I tried doing simply request.getRequestDispatcher("/mypage.jsp").include(request, response); but this invokes the servlet and causes a loop.

                --
                Cheers,
                Adam

                • 5. Re: Filter and servlet mappings
                  adamw

                  Hello,

                  I solved the problem by mapping the servlet to /, and thus making it the default servlet. Then the requests for the JSP page go where they shold. Though I thught that when there are two overlapping mappings specified, one more and one less specific, the more specific is used in case of an path that matches both.

                  --
                  Cheers,
                  Adam