HttpServletResponse.sendRedirect() method


Web tier: servlets, JSP, Web frameworks: HttpServletResponse.sendRedirect() method

  1. HttpServletResponse.sendRedirect() method (3 messages)

    Maybe someone can answer this. How does the sendRedirect method work? Does it depend on browser support (in other words, possibly not all browsers support it)? The browser is actually sent to a new URL, which shows up in the browser's address bar... I was just wondering how this works, if it uses some http header, etc.
  2. Not that your question has anything to do with Struts, I do explain in somewhat detail how a redirect diffs from a forward in Chapter 2 of my upcoming O'Reilly book on Struts.

    You can download chapter 2 from right here on this site:

    Take a look at that section in Chapter 2 and see if it helps make things clearer.

  3. Thank you, that was very informative. Do all or most browsers automatically redirect to the new URL? It would be awkward and undesirable if in the middle of navigating your application, a user encountered some "This page has temporarily moved" error screens.
  4. To my knowledge, this behavior is part of the specification and all compliant browsers should know how to handle a 302 and request the new URL. I'm not sure if any browser has the ability to turn off being redirected. I haven't seen an option like that, but it might exist on one of them.

    I think redirection is a pretty common occurrence.