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 ]
Joined: Nov 01, 2002
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?
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