Wednesday 4 August 2010

When to use redirect en when to use forward

This is just to remind me.

These are the two and the differences:

  • response.sendRedirect("http://www.xyz.com")

    • send a redirect request back to the browser
    • is slow
    • will change the location
  • pageContext.forward("http://www.xyz.com") and requestDispatcher.forward("http://www.xyz.com")

    • sends a forward request right onto the next page/jsp
    • is faster
    • will not change the location
    • you still have access to the original request
  • pageContext.include("http://www.xyz.com") and requestDispatcher.include("http://www.xyz.com")

    • includes a request into the current page/jsp
    • will not change the location
    • you still have access to the original request
    • you can continue processing when you get back control
    • good for including content from another page

No comments:

Post a Comment