filmov
tv
214 Key Points of javax.servlet.Filter life cycle | Advanced java servlet tutorial | Servlet filter

Показать описание
2) Following are the Servlet filter program life cycle methods:
init(FilterConfig),
doFilter(ServletRequest, ServletResponse, FilterChain),
destroy()
filter, filter-mapping tags.
8) There is no FilterContext object but FilterConfig object can be used to get access to ServletContext object.
API Version and Features:
-------------------------
Servlet 2.1 : Added extra methods in existing interfaces and Abstract Class
Servlet 2.2 : ServletListeners
Servlet 2.3 : ServletFilters
Servlet 3.0 : Annotations
Create sample Filter programs:
public void init(FilterConfig cg){
--------//initialization logic
}
public void doFilter(ServletRequest req, ServletReponse res, FilterChain fc)throws Exception{
-------//pre-request processing logic
-------
//passes the request to servlet pgm with whom its linked/mapped
doFilter(req,res);
-------
-------// post-response generation logic
}
public void destroy(){
--------// un-initialization logic
}
}
- knowingly/unkowingly we must and should have to override OR redefine the lifecycle methods in our programmer defined filter program.