Larry Brown, Marty Hall, and Yaakov Chaikin
"Core Servlets and JavaServer Pages, Volume 2"
e., the start time is on one day and
// the end time is on the next day), then the current
// time is considered unusual if it is NOT between
// the end and start times.
else {
return(!isUnusualTime(currentTime, endTime, startTime));
}
}
}
Listing 5.10 LateAccessFilter.java (continued)
Chapter 5 ?– Servlet and JSP Filters 226
5.7 Blocking the Response
Up to now, all the filters discussed have concluded their doFilter methods by calling
the doFilter method of the FilterChain object. This approach is the normal
one??”the call to doFilter invokes the next resource in the chain (another filter or
the actual servlet or JSP page).
But what if your filter detects an unusual situation and wants to prevent the original
resource from being invoked? How can it block the normal response? The answer
is quite simple: Just omit the call to the doFilter method of the FilterChain
object. Instead, the filter can redirect the user to a different page (e.g., with a call to
Listing 5.11 web.xml (Excerpt for access time filter)
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">