How do you redirect in JSP and in Struts?

Showing Answers 1 - 9 of 9 Answers

nirajthacker

  • Sep 26th, 2007
 

If you use response.sendRedirect("path") you will lose your request object.
Use requestDispatcher.forward("path") to retain your request object.

  Was this answer useful?  Yes

mabhijit

  • Jan 11th, 2008
 

There are two ways to redirect a request from JSP. They are
1). response.sendRedirect("Path");
2). requestDispatcher.forward("path");
Now the difference b/t these two are :-
1).sendRedirect() does not pass request and response object, forward() passes req and res objects. Means new request is created in the sendRedirect method but forward() passes the same request object in the chaining.
2). When we use sendRedirect method then u r changing or transfering the request to new URL.Mean new URL is formed .In case of Forward method of RequestDispatcher your context is not changed means ur URL object remains same
3). If we want to send a request in inter-application then we can use sendRedirect().
4). In forword() the request is sent to another page with in the webapplication only. where as sendredirect() will sent the respone to another web application.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions