permaculture playing cards*
The moose likes Servlets and the fly likes include, forward and redirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "include, forward and redirect" Watch "include, forward and redirect" New topic
Author

include, forward and redirect

Sachin Ramesh Vir
Greenhorn

Joined: Sep 15, 2005
Posts: 23
Hi,

What is the differences between the 'include' ,'forward' and 'redirect'?
[ September 26, 2005: Message edited by: Sachin Ramesh Vir ]
kuni patel
Greenhorn

Joined: Jun 04, 2005
Posts: 7
i think::::

include: this is used for include any file to yr application
like in servlet:
RequestDispatcher rd=srq.getRequestDispatcher();
rd.include("/*put here yr path from where u want to get file for attachment*/");

forward:this isuseful for forwarding request to another page.

like: rd.forward("/*wright yr path where u want to go with request*/");

redirect:
this is useful for forwarding to another page without attaching request.


Thanx
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Sachin, this is a very common question, a useful link is here.

kuni, thanks for answering questions, we appreciate it! But please try to UseRealWords.

thanks
Dave
Sachin Ramesh Vir
Greenhorn

Joined: Sep 15, 2005
Posts: 23

3) RequestDispatcher .forward
No response is send to the browser, the web container internally redirects the request to the other page. Remember , you can redirect only to a page within current servlet context.
Also there are two flavours of RequestDispatcher , one : you get from ServletContext .The pathname must begin with a "/" and is interpreted as relative to the current context root.
Second : you get from ServletRequest. The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root


The above quote has been taken from one of the thread in this forum for that question: "Diff btw response.sendRedirect, jsp:forward and RequestDispatch .forward methods? "

I can't the understand the following lines:


Remember , you can redirect only to a page within current servlet context.





The pathname must begin with a "/" and is interpreted as relative to the current context root.The pathname specified may be relative, although it cannot extend outside the current servlet context.





The pathname specified may be relative, although it cannot extend outside the current servlet context.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: include, forward and redirect