Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use of forward and sendRedirect  RSS feed

 
ravindra patil
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to Servlet programming,can anybody please explain me in situation i have to use forward method and in situation use sendRedirect().
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A forward transfers control of the current request to another resource. A redirect contacts the browser to tell it to make a new request.

You base your decision upon which one to use based upon whether you want to continue processing the current request or initiate another.
 
Zotal warlord
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, when you use requestdistpatcher, is there any way to keep the jsp address in the url bar, instead of the servlet one?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Zotal warlord",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted, often without warning

thanks,
Dave
 
Saurabh Chaubey
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, when you use requestdistpatcher, is there any way to keep the jsp address in the url bar, instead of the servlet one?


The use of forwarding or including happens on the server side only.here the server contacts other resources on the server itself, while in redirecting the server asks the client's browser to generate a new request with the new url provided for redirection. the new resource could be located anywhere. So the use of requestdistpatcher contains only the current request while the use of redirection generates a new request that is why the url also changes to the new one while redirecting.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!