Skip to Content
Head First Servlets and JSP, 2nd Edition
book

Head First Servlets and JSP, 2nd Edition

by Bryan Basham, Kathy Sierra, Bert Bates
March 2008
Intermediate to advanced
911 pages
20h 31m
English
O'Reilly Media, Inc.
Content preview from Head First Servlets and JSP, 2nd Edition

News Flash: As of version 2.4, filters can be applied to request dispatchers

Think about it. It’s great that filters can be applied to requests that come directly from the client. But what about resources requested from a forward or include, request dispatch, and/or the error handler? Servlet spec 2.4 to the rescue.

Declaring a filter mapping for request-dispatched web resources

<filter-mapping>
  <filter-name>MonitorFilter</filter-name>
  <url-pattern>*.do</url-pattern>
  <dispatcher>REQUEST</dispatcher>

        - and / or -

  <dispatcher>INCLUDE</dispatcher>

        - and / or -

  <dispatcher>FORWARD</dispatcher>

        - and / or -

  <dispatcher>ERROR</dispatcher>
</filter-mapping>

Declaration Rules

  • The <filter-name> is mandatory.

  • Either the <url-pattern> or <servlet-name> element is mandatory.

  • You can have from 0 to 4 <dispatcher> elements.

  • A REQUEST value activates the filter for client requests. If no <dispatcher> element is present, REQUEST is the default.

  • An INCLUDE value activates the filter for request dispatching from an include() call.

  • A FORWARD value activates the filter for request dispatching from a forward() call.

  • An ERROR value activates the filter for resources called by the error handler.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Head First Java, 2nd Edition

Head First Java, 2nd Edition

Kathy Sierra, Bert Bates
Head First Java, 3rd Edition

Head First Java, 3rd Edition

Kathy Sierra, Bert Bates, Trisha Gee
Learning Java, 6th Edition

Learning Java, 6th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 9780596516680Errata PageSupplemental Content