Getting hold of the servlet context within a filter
How can I get hold of the servlet context from within a filter?
How can I get hold of the servlet context from within a filter?
By FilterConfig#getServletContext().
The Filter has a FilterConfig that contains the ServletContext.
class myFilter implements Filter {
private FilterConfig config;
public void init(FilterConfig filterConfig)
throws ServletException {
this.config = FilterConfig;
}
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws java.io.IOException,
ServletException {
ServletContext context = this.config.getServletContext();
}
}