Bill Lynch wrote:

> Kenia,
>
> There are a few ways to do this and I think you might be interested in
> directly manipulating one servlet from another.
>
> For instance, if you're in servlet B, you could first call a method in
> servlet A's object (this method would print out the record based on the
> booking number) then you could print out the additional information that
> B handles.
>
> Use Java's language reflection (this requires you know what method
> you're looking for in A):
>
> Servlet serv = context.getServlet("THE_NAME_OF_SERVLET_A");
> Method myMethod =
> servlet.getClass().getMethod("THE_NAME_OF_SERVLET_As_METHOD",null);
> myMethod.invoke(servlet,null);
>
> These methods throw a few exceptions so you'll have to wrap this in a
> try/catch block. (I believe 4 of them!)
>

Exception catching is the least of your problems.  In a servlet engine
compliant with the 2.1 API spec, the getServlet() call has been deprecated,
and it is required to return NULL.  Thus, you will no longer be able to access
a different servlet instance at all.  The good reasons for this change are far
too numerous to list, even though it will be disruptive to existing servlets
that rely on getServlet().

You are *strongly* encouraged to use techniques such as session variables to
share objects between different servlets, or between different requests to the
same servlet, for the same user.

Craig McClanahan

___________________________________________________________________________
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

Reply via email to