views:

163

answers:

1

Could anyone please tell me why the following line about filter init method invocation is incorrect:

The init method on a filter is called the first time a servlet mapped to that filter is invoked.

+2  A: 

Because it's called when filter is loaded and initialized by servlet container, which happens during web application startup. Filter's init() method will be called even if it will never intercept a single request.

From the API documentation:

void init(FilterConfig filterConfig) throws ServletException

Called by the web container to indicate to a filter that it is being placed into service. The servlet container calls the init method exactly once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work.

ChssPly76