Jorge Saenz wrote:

> hello,
>
> could anybody say me if it�s possible making a servlet to invoke a method
> of another servlet that is loaded in the same server???
>
> thanks...and regards
>
>           Jorge
>

Under the 2.0 API, this is possible -- you can use ServletContext.getServlet()
to get a reference to another servlet, and then call its methods like any
other Java class.

However, this is a very bad idea (for lots of reasons that have been hashed
over and over on this list).  In any case, the arguments are now academic,
because the 2.1 API has deprecated the getServlet() call, with no
replacement.  Thus, you need to go back to why you want to do this in the
first place.

Examples of reasons you might want to, and what to do about them:

* Gain access to shared data --> store shared
  data objects with ServletContext.setAttribute()
  (if global) or HttpSession.putValue() (if private
  to a user).

* Include the output of one servlet in the page
  generated by another --> Use RequestDispatcher.include

* Call common utility functions coded in one
  servlet --> Redesign your code to separate
  out the common functions into a non-servlet
  class that you can address directly.

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