aspose file tools*
The moose likes Servlets and the fly likes forward vs include vs sendRedirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "forward vs include vs sendRedirect" Watch "forward vs include vs sendRedirect" New topic
Author

forward vs include vs sendRedirect

Muralidhar Gandepalli
Greenhorn

Joined: Apr 16, 2001
Posts: 15
Can some body answer these questions please
1)Can somebody compare RequestDispatcher.include(..), RequestDispatcher.forward(..) and HttpServletResponse.sendRedirect(..)?
2)For a servlet ,I feel that destroy() becomes a sort of redundant because we can use finalize() to achieve what ever we want to using destroy ? Please throw some light if iam missing something here....
Thanx in advance
[ May 27, 2003: Message edited by: Muralidhar Gandepalli ]
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
If you want to use the request or response object in the JSP you are forwarding to, then you'll need to use RequestDispatcher.forward()


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

RequestDispatcher.include() processes the named resource and includes its output at the point of inclusion.
RequestDispatcher.forward() takes the entire current request environment and transfers it to the named resource. You cannot forward once output has been comitted.
HttpServletResponse.sendRedirect() causes a new request to be created by the client. The old request environment is not maintained. You also cannot redirect once output has been committed.
destroy() is called by the container when the servlet is unloaded. finalize() is part of garbage collection and cannot be counted upon to be called in any deterministic fashion. If your servelet must manage resources (close DB connections, for example) when shut down, you should rely upon destroy().
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: forward vs include vs sendRedirect
 
Similar Threads
JBossCache vs. GigaSpaces
filters vs RequestDispatcher's include() method
Thread vs Runnable
IBM HTTP Server vs Apache vs WAS ?
ORM vs JDBC