title: Filters: client and server side redirecting
body: <p>That's my filter:</p>
  
  <pre><code>public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
          throws java.io.IOException, javax.servlet.ServletException
  {
      HttpServletRequest request = (HttpServletRequest) servletRequest;
      HttpServletResponse response = (HttpServletResponse) servletResponse;
      String currentURL = request.getRequestURI();
      MaintenanceService maintenanceMode = new MaintenanceService();
  
      if (maintenanceMode.getMaintenanceMode())
      {
          String urlNew = currentURL.concat("maintenance.jsp");
          response.sendRedirect(urlNew);
  
      }
      filterChain.doFilter(servletRequest, servletResponse);
  }
  </code></pre>
  
  <p>"under" maintenanceMode.getMaintenanceMode(), I have variable getter: </p>
  
  <pre><code>boolean maintenanceMode = Boolean.getBoolean("maintenance");
  </code></pre>
  
  <p>With <em>forward</em> (server-side redirect) it works fine, when I'm trying client-side redirect:</p>
  
  <pre><code>response.sendRedirect(urlNew);
  </code></pre>
  
  <p>I got an infinite occurrences maintenance.jsp concatenating:</p>
  
  <pre><code>http://localhost:8080/maintenance.jspmaintenance.jspmaintenance.jspmaintenance.jspmaintenance.jsp
  </code></pre>
  
  <p>why it's not redirecting onto one occurrence, like with server-side redirect:</p>
  
  <pre><code>http://localhost:8080/maintenance.jsp
  </code></pre>
  
  <p>Web.xml filter mapping:</p>
  
  <pre><code>&lt;filter-mapping&gt;
      &lt;filter-name&gt;maintenanceFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>