| Author |
Cmmunication between two servlets?
|
Tom Barns
Ranch Hand
Joined: Oct 27, 2000
Posts: 138
|
|
Hi All I'm trying to implement communication between two servlets,but the problem that I'm facing is depracated methods as getServlet("name") and others ,so please if you have two very simple servlets to show how they communicate, that will be great. thanks
|
Thanks for your help.
|
 |
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
|
|
Originally posted by Tom Barns: I'm trying to implement communication between two servlets,but the problem that I'm facing is depracated methods as getServlet("name") and others
I don't have sample code for you, unfortunately, but the gist is this. Sun deprecated getServlet because the direct servlet-servlet interaction it allows encourages bad practice. If you want two servlets to communicate, one servlet can forward a request to the other (getServletConfig().getServletContext().getRequestDispatcher("/secondServlet").forward(req, res)). Any parameters that need to be communicated can be incorporated as part of the request (e.g. req.setAttribute("name", myObject)). Sometimes the relevant state may be session-scoped (req.getSession().setAttribute("name", myObject)) or even application-scoped (getServletConfig().getServletContext().setAttribute("name", myObject)). Carefully synchronize any thread-unsafe code though. If a forward doesn't fit the bill, you can also use include. Should neither model be what you want, then there is probably some shared functionality in your servlets that really wants to be factored out into a bean or other Java object. - Peter [This message has been edited by Peter den Haan (edited February 12, 2001).]
|
 |
 |
|
|
subject: Cmmunication between two servlets?
|
|
|