Monday, September 24, 2007

RequestDispatcher.forward() and filters

If you have read this post then you probably know that if you use RequestDispatcher.forward() (or RequestDispatcher.include()) the filter chain does not get re-called for the forwarded servlet/jsp. However, if you read more closely you see that Craig was talking about the 2.3 servlet spec. Since we are using tomcat 5.5 which conforms to the 2.4 spec, you should know that there's a new <dispatcher> element in the deployment descriptor with possible values REQUEST, FORWARD, INCLUDE, and ERROR. You can add any number of entries to a <filter-mapping> tag and individually decide which filter gets called when. An Example:


<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>SecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

12 comments:

  1. tHANKS DUDE, U JUST MADE MY DAY ;)

    ReplyDelete
  2. thank you Nir,
    I'll try to explain to my pupils

    ciao!
    from sevilla spain

    ReplyDelete
  3. Sweet...that's exactly what I was looking for. Thanks!

    ReplyDelete
  4. now my dispatcher works gr8! thanks

    Christoph

    ReplyDelete
  5. Thank you! I have been trying to figure this out all day!

    ReplyDelete
  6. Thnak you, works like a charm!

    ReplyDelete
  7. Really THANKS !
    You have saved our week whit those short 7 lines... ;-)

    ReplyDelete
  8. Thnks a lot! Really helpful.

    ReplyDelete
  9. Thanks Man! It helped a lot!!

    ReplyDelete
  10. Thanks for the details.
    Exactly what I was looking for !!!

    ReplyDelete

[Due to much spam, comments are now moderated and will be posted after review]