• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

forward vs include vs sendRedirect

 
Muralidhar Gandepalli
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic