SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 266 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"

-->

LateAccessFilter

coreservlets.filters.LateAccessFilter


startTime
2


endTime
10




LateAccessFilter
/index.jsp


5.8 Example: A Prohibited-Site Filter 227
response.sendRedirect) or generate the response itself (e.g., by calling get-
Writer on the response and sending output, just as with a regular servlet). Just
remember that the first two arguments to the filter??™s main doFilter method are
declared to be of type ServletRequest and ServletResponse. So, if you want
to use methods specific to HTTP, cast these arguments to HttpServletRequest
and HttpServletResponse, respectively. Here is a brief example:
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest)request;
HttpServletResponse res = (HttpServletResponse)response;
if (isUnusualCondition(req)) {
res.sendRedirect("http://www.somesite.com");
} else {
chain.doFilter(req,res);
}
}
5.8 Example: A Prohibited-Site Filter
Suppose you have a competitor that you want to ban from your site.


Pages:
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278