• Post Reply Bookmark Topic Watch Topic
  • New Topic

forward

 
pravanya kantipudi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have some doubts in servlets.

1) forward method dispatches the resuest to another resource. it only dispatches the request or it dispatches the response also?

2) there is one abc.jsp page . and when we invoke sendredirect method it moved to xyz.jsp page.

is request in abc.jsp page available in xyz.page?

thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first question can by answered by the API:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/RequestDispatcher.html#forward(javax.servlet.ServletRequest,%20javax.servlet.ServletResponse)
(Look at the argument list in the signature of the forward method)

The answer to the second question is no.
Unlike a forward, the sendRedirect method works by sending a response to the browser asking it to make a brand new request for the other page.
If you install a packet sniffer or a tool like the LiveHttpHeaders plugin for FireFox, you can see all of this happen in the request and response headers.
[ July 01, 2007: Message edited by: Ben Souther ]
 
Sudhakar Kalk
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pravanya kantipudi:
i have some doubts in servlets.

1) forward method dispatches the resuest to another resource. it only dispatches the request or it dispatches the response also?

2) there is one abc.jsp page . and when we invoke sendredirect method it moved to xyz.jsp page.

is request in abc.jsp page available in xyz.page?

thanks


1.Same request and response objects created for the first resource will be dispatched to the second resource when making use of forward().

2.sendRedirect() makes use of new request and response objects in another resource.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:


If you install a packet sniffer or a tool like the LiveHttpHeaders plugin for FireFox, you can see all of this happen in the request and response headers.



Thanks!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sudhakar K ",
Welcome to JavaRanch!

We're pleased to have you here with us here on the ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. You can change it here
[ July 03, 2007: Message edited by: Ben Souther ]
 
reddy bharath
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually both servlets use the same request and response objects,

the output generated by the first servlet will be discarded,u can only get the output of second servlet

in case of sendredirect the browser will be sending the new request,it'll create new request and response objects

hope it is clear now
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!