Even if you come up with a solution that appears to work, this is going to
fail as soon as you try it under a servlet engine that supports the 2.1 API,
because getServlet() is deprecated and required to return NULL. However, even
with current servlet engines, this approach will fail -- there is absolutely
no guarantee that there is only one instance of your ICDesk servlet in
existence, so you have no guarantees that the objects you are trying to share
really can be shared.
It appears that you are using the "master servlet" primarily to store data
items. The fact that it is a servlet is indicative of an error in design --
you are trying to use a servlet for data storage. Servlets should *only*
create dynamic pages, or serve as the glue that ties together other dynamic
page generation tools such as JSP pages or page template generation tools.
If you want to share data items between serviets (or between separate requests
for the same servlet), your best design approach is one of the following:
* If the variables you are sharing are unique to a particular user,
store then in an HttpSession with the putValue() command.
* If the variables really do need to be shared across servlets,
store them with ServletContext.setAttribute() in a 2.1-compliant
servlet engine, or use the Singleton pattern (a class that has
only static variables and methods) in a 2.0-compliant
servlet engine.
Craig McClanahan
Oliver Pistor wrote:
> Hi,
>
> after reading all about inter-servlet comm. and NOT being sure
> of having understood it all correctly, I came up with the following design:
>
> 1. "Master Servlet": Stores all "handles" to the several servlets:
>
> public class ICDesk extends HttpServlet
>
> (...)
>
> public static DBQuery q;
> public static HTMLUtil h;
> public static ICUser u;
> public static ICDesk d;
>
> (...)
>
> public void doPost (HttpServletRequest req, HttpServletResponse res) throws
> ServletException, IOException {
>
> q = (DBQuery) getServlet(req, "DBQuery");
> h = (HTMLUtil) getServlet(req, "HTMLUtil");
> u = (ICUser) getServlet(req, "ICUser");
> d = (ICDesk) getServlet(req, "ICDesk");
>
> (...)
> }
>
> 2. "Slaves" - One slave as an example:
>
> public class ICNotes extends HttpServlet
>
> private ICDesk d;
> private DBQuery q;
> private HTMLUtil h;
> private ICUser u;
>
> (...)
>
> public void doPost (HttpServletRequest req, HttpServletResponse res) throws
> ServletException, IOException {
>
> d = ICDesk.d;
> q = ICDesk.q;
> h = ICDesk.h;
> u = ICDesk.u;
>
> (..)
> }
>
> I'd like to now what a experienced Servlet programmers would say to this.
> Does this solve the class loader issue or am I just lucky?
> (I use Servlet SDK 2.0 not 2.1 !)
>
> Thanx
>
> Oliver
>
> Mit freundlichen Gr��en
>
> Oliver Pistor
>
> -----------------------------------------------------------------------
> Oliver Pistor
> dsa Solutions
> Pf�lzer Str.6
> 69123 Heidelberg
>
> Tel.: 06221 839 513
> Mobil: 0172 761 9365
> Fax: +49 6221 472675
>
> [EMAIL PROTECTED]
> http://www.dsa-solutions.de
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html