• Post Reply Bookmark Topic Watch Topic
  • New Topic

Forward in JSP  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys....I have been Haunted by this question by number of Interviewers . It's Kind of a pet question of the panel .
1) WHAT ARE THE DIFFERENT WAYS TO FORWARD TO ANOTHER RESOURCE IN JSP .
My Ans :- Using JSP Forward Tag , Using The RequestDispatcher interface method sendRedirect() or using the response.sendRedirect() method .
On hearing this , mostly I'am asked what are the differences in these three methods. could any one point out please !!!

Thanx in Advance !
 
bharat nagpal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The forward method works inside the Web container. The sendRedirect method requires a round trip to the client. So the forward method is faster than sendRedirect. However, using the forward method restricts you to redirect only to a resource in the same Web application. The sendRedirect method, on the other hand, allows you to redirect to any URL.

RequestDispatcher.forward() and PageContext.forward() are effectively the same. PageContext.forward is a helper method that calls the RequestDispatcher method.
the <jsp:forward..> is a forwarding of your request. What this means is that your request parameters (the request object)_ still remains current and you canstill access all its parameters. On the other hand the sendRedirct() is a NEW REQUEST. you loose all your request parameters. As you might guess <jsp:forward..> is faster. however it does have some problems specially when someone decides to lets say reload a page. The request will be sent again
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx bhart ....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!