> But in 2.1, it always return null.
>
> Is there any solution for this?
getServlet isn't a safe method. An entirely different (but better)
approach is necessary.
To get functionality where you access the same logic or data structure
from two servlets, place an object by a well known name into the
ServletContext attribute list. For example (in incomplete psudocode):
public class Servlet1 {
MyObject mo;
public void init() {
// synch on the context object so that only one servlet
// at a time will grab the object attached to foo or
// create it as needed.
synchronized(context) {
mo = (MyObject)context.getAttribute("foo");
if (mo == null) {
mo = new MyObject();
context.setAttribute("foo");
}
}
}
public void doGet(req, res) {
// now you can use mo to do anything you need!
// share any data you want to, etc.
mo.dosometing();
mo.counterIncrement(); // whatever...
}
}
public class Servlet2 {
// same as the first
}
___________________________________________________________________________
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