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 242 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"

For simple filters, most of your filter logic is based on this object. Cast
the object to HttpServletRequest if you are dealing with HTTP requests
and you need access to methods such as getHeader or getCookies that are
unavailable in ServletRequest.
The second argument is the ServletResponse. In simple filters you
often ignore this argument, but there are two cases when you use it. First, if
you want to completely block access to the associated servlet or JSP page, you
can call response.getWriter and send a response directly to the client.
Section 5.7 (Blocking the Response) gives details; Section 5.8 (Example: A Prohibited-
Site Filter) gives an example. Second, if you want to modify the output
of the associated servlet or JSP page, you can wrap the response inside an
object that collects all output sent to it. Then, after the servlet or JSP page is
invoked, the filter can examine the output, modify it if appropriate, and then
send it to the client. See Section 5.9 (Modifying the Response) for details.
The final argument to doFilter is a FilterChain object. You call
doFilter on this object to invoke the next filter that is associated with the
servlet or JSP page. If no other filters are in effect, then the call to doFilter
invokes the servlet or JSP page itself.
public void init(FilterConfig config)
throws ServletException
The init method is executed only when the filter is first initialized.


Pages:
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254