title: Redirect from login interceptor in Struts 2
body: <p>Our application requires users to be logged in to view any content. Access to all pages is intercepted by <code>LoginInterceptor</code> which brings up the login form if there's no valid session for the user.</p>
  <p>I'd like the interceptor to remember the original request URI before displaying the login form and redirect to it if the login form validation is successful.</p>
  <p>I tried to follow <a href="https://stackoverflow.com/questions/18410407/struts-2-redirect-to-correct-action-after-authentication-interceptor">Struts 2 Redirect to correct action after authentication interceptor</a>.</p>
  <pre><code>@Service
  @Results({
      @Result(name = &quot;redirect&quot;, type = &quot;redirect&quot;, location = &quot;${savedUrl}&quot;)
  })
  public class LoginInterceptor extends AbstractInterceptor {
      //...
      private String savedUrl;
      //...
      @Override
      public final String intercept(final ActionInvocation invocation) throws Exception {
         // ...
         savedUrl = (String) session.getAttribute(&quot;savedUrl&quot;);
         // ...
         if (processLogin(request, session)) { // validate login form
             if (!StringUtils.isEmpty(savedUrl)) {
                return &quot;redirect&quot;;
             }
             return LOGIN_SUCCESS_RESULT;
         }
         // if there's no loginData in sesssion, remeber the URI and display a login form
         String queryString = request.getQueryString();
         session.setAttribute(&quot;savedUrl&quot;, request.getRequestURI() + (queryString==null ? &quot;&quot; : (&quot;?&quot; + queryString)));
         return &quot;login&quot;;
      }
      // ...
      public String getSavedUrl(){
         return savedUrl;
      }
  }
  </code></pre>
  <p>However I get a blank page as a result of <code>return &quot;redirect&quot;</code>.  <code>getSavedUrl()</code> is never called.</p>
  <p><strong>Solution:</strong></p>
  <p>Scratch the <code>@Results</code> annotation completely and instead of <code>return &quot;redirect&quot;;</code> call</p>
  <pre><code>response.sendRedirect(savedUrl); return null;
  </code></pre>