title: Is there a solution to keep a cookie on browser while redirect the response?
body: <p>I am building a user tracking system for a web application. People could came from many urls. I want to know from which urls the came from.
  I design url like this : <a href="http://www.example.com/ref/XXXXXXX" rel="nofollow">http://www.example.com/ref/XXXXXXX</a>.</p>
  
  <p>I create a Filter to handle incoming request :</p>
  
  <pre><code>String cookieKey = "examplesite.cookie";
  String cookieValue = referralIdentifier;
  Cookie cookie = new Cookie(cookieKey, cookieValue);
  cookie.setMaxAge(60*60*24*365);
  ((HttpServletResponse) response).addCookie(cookie);
  
  HttpServletResponse resp = (HttpServletResponse)response;
  resp.addCookie(cookie);
  resp.sendRedirect("/");
  </code></pre>
  
  <p>When this code execute, I cannot see the cookie set in the browser. </p>
  
  <p>If I change the redirect to forward, I can see the cookie.
  The I see this blog post <a href="https://www.elie.net/blog/security/tracking-users-that-block-cookies-with-a-http-redirect" rel="nofollow">how to track people with cookie and redirect</a> where the blogger suggest to use code to redirect.</p>
  
  <p>So I changed my code and I replace <code>resp.sendRedirect("/");</code> by </p>
  
  <pre><code> resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                          resp.setHeader("Location", "http://www.example.com/");
  </code></pre>
  
  <p>Here I can see the cookie in Firefox but not in Chrome. </p>
  
  <p>Is there a solution to track user after redirection ?</p>