This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

jsp:forward and res.sendRedirect()

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i got the last question wrong. I read somewhere that fsp:forward can ONLY forward to a URL on the local server (or within the same context ?) while this is not so with sendRedirect()?
Isn't this a big limitation then ?
sree bk
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it could be looked at as limitation, but with <jsp:forward> you can also send parameters to the next page. Sure you can do it using: res.sendRedirect("");, but then you will see what you've sent once the redirected page is loaded, with jsp:forward I don't think you will.
Posts: 3226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From (Top Ten JSP Tips)
4.Choosing Between Forward and Redirect
If you want to pass the control from one page to another, you can either
forward to the other page, as described above, or redirect to the new page
(using the sendRedirect() method of the implicit response object).
There's an important difference between a forward and a redirect. When
you forward, the target page is invoked by the JSP container through an
internal method call; the new page continues to process the same request
and the browser is not aware of the fact that more than one page is
involved. A redirect, on the other hand, means that the first page tells the
browser to make a new request to the target page. The URL shown in the
browser therefore changes to the URL of the new page when you redirect,
but stays unchanged when you use forward. A redirect is slower than a
forward because the browser has to make a new request. Another difference
is that request scope objects are no longer available after a redirect because
it results in a new request. If you need to pass data to the page you redirect
to, you have to use a query string and pass them as request parameters (or
save the data as session or application scope objects).
So how do you decide if you should use forward or redirect? I look at it
like this: Forwarding is always faster, so that's the first choice. But since
the URL in the browser refers to the start page even after the forward, I ask
myself what happens if the user reloads the page (or just resizes the
window; this often reloads the page automatically). If the start page is a
page that updates some information, such as adding an item to the shopping
cart or inserting information in a database, I don't want it to be invoked
again on a reload. To show the result of the processing, I therefore redirect
to a page with a confirmation message, instead of using forward.
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic