Hello! Please help with the code ..

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) resp; String requestURI = request.getRequestURI(); System.out.printf("LoginFilter.doFilter(): requestURI = %s; ", requestURI); String loggedInToken = (String)request.getSession().getAttribute(LoginConstants.LOGIN_FLAG); if (loggedInToken != null) { // User is logged in, continue processing, override getRemoteUser in request object. System.out.printf("user is %s%n", loggedInToken); chain.doFilter(new LoginFilterHTTPServletRequest((HttpServletRequest) req, loggedInToken), resp); return; } 

===============================================

The logic of this string is incomprehensible .. After checking "loggedInToken! = Null", the user button will be printed, after which I will be lost .. I will be glad to have some ideas ..

  chain.doFilter(new LoginFilterHTTPServletRequest((HttpServletRequest) req, loggedInToken), resp); return; 
  • Next comes the call to the next filter in the chain (chain) of the filters. There may be several filters and they are lined up. To go to the next filter or servlet (if this filter is the last one), chain.doFilter() called. If the chain not called, the request processing will end on this filter. Here is an explanation with pictures, although if you do not know aglitsky at all, then the pictures will not help. docs.oracle.com/cd/B32110_01/web.1013/b28959/filters.htm - Sergey
  • Thanks for the link, with English excellent. Read .. - Maks.Burkov
  • In addition, a filter can replace request and response , usually passing its wrapper around the received request and response to the next filter. What we see in the example of LoginFilterHTTPServletRequest . This filter probably wants to implement the loggedInToken property in the request . In the standard request there is no such property, therefore it replaces it with its wrapper. - Sergey
  • Can you give an example of why you need to replace received Request & Response? - Maks.Burkov
  • I can not. Himself never had a need to replace. And the examples sucked from the finger in the books are better written. - Sergey

0