Hello! I am a beginner in the use of web technologies in Java .. I came across this code on the Internet .. I can not understand what is the point in creating filters, for example, like this one.
The doFilter() method of the Filter Chain class is not clear. The documentation says: What is this method:
In the chain of water, it can be invoked
Perhaps the question is stupid, but because of the lack of understanding of absolutely this topic I wanted to ask: What is the next filter in turn? (What does it mean to wake up as I understand it when translating into Russian) "Next filter"? Any examples will help to understand the very idea of this functionality .. References on the topic if anyone can advise, too, will help!
public class AuthFilter implements Filter { private FilterConfig filterConfig; @Override public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("doFilter is execute"); HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.sendRedirect("login.jsp"); //chain.doFilter(request, response); } @Override public void destroy() { this.filterConfig = null; } }