@Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        if (!(req instanceof HttpServletRequest &&
                res instanceof HttpServletResponse)) {
            throw new ServletException("non-HTTP request or response");
        }

        this.doFilter((HttpServletRequest)req, (HttpServletResponse)res, chain);
    }
@ Override public void doFilter ( ServletRequest req , ServletResponse res , FilterChain chain ) throws IOException , ServletException { if ( ! ( req instanceof HttpServletRequest && res instanceof HttpServletResponse ) ) { throw new ServletException ( "non-HTTP request or response" ) ; } this . doFilter ( ( HttpServletRequest ) req , ( HttpServletResponse ) res , chain ) ; }
<p>The <code>doFilter</code> method of the Filter is called by the
container each time a request/response pair is passed through the
chain due to a client request for a resource at the end of the chain.
The FilterChain passed in to this method allows the Filter to pass
on the request and response to the next entity in the chain.  There's no need to
override this method.</p>

<p>The default implementation inspects the incoming {@code req} and {@code res}
objects to determine if they are instances of {@link HttpServletRequest}
and {@link HttpServletResponse}, respectively.  If not, a {@link ServletException} is thrown.
Otherwise, the protected {@link #doFilter(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.FilterChain)}
method is called.</p>

@param req   a {@link ServletRequest} object that
contains the request the client has made
of the filter

@param res  a {@link ServletResponse} object that
contains the response the filter sends
to the client

@param chain     the <code>FilterChain</code> for invoking the next filter or the resource

@throws IOException   if an input or output error is
detected when the filter handles
the request

@throws ServletException  if the request for the could not be handled or
either parameter is not an instance of the respective {@link HttpServletRequest}
or {@link HttpServletResponse}.

@since Servlet 4.0