----------------------------------------------------
Please read the FAQ at <http://java.apache.org/faq/>
It does have a search feature!
We cannot guess what you are trying to do:
#1. Include version numbers for all software.
#2. Include relevant configuration settings.
#3. Include full descriptions of the problem.
Got Linux? Seeing lots of java processes?
<http://java.apache.org/faq/?file=274>
----------------------------------------------------
I have personally used the inheritance method and would say that it works
fine. Here is the jist of what you need to do:
Super Class:
public class MySuperClassServlet extends HttpServlet {
static String msg = "Hello World"; // I know it is corny, but...
static Vector list;
// add what ever else you need;
public void init(ServletConfig config) throws ServletException {
super.init(config);
if (list == null) list = new Vector();
}
}
Child Class(es):
public class MyClassServlet extends MySuperClassServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
}
And that is it... All the children class can access the variable "list"
with no problems. I can also suggest another way that I have done(
although not in servlets, but within the same VM not the less..), is to
create a data object that is keeps all the data as static variables and
encapsulate their access from the outside through methods:
public class DataHolderObj {
private static boolean first_creation = true;
private static String msg = null;
private static int value;
public DataHolderObj() {
if (first_creation) {
msg = "Hello World";
value = 0;
first_creation = false;
// so that initialization is only ever done once.
}
}
public synchronized void setMessage(String str) { msg = str; }
public String getMessage() { return msg; }
public synchronized void setValue(int new_value) {
value = new_value;
}
public int getValue() { return value; }
}
Althought the second method works, there are 2 draw back 1) Lots of
work involved and 2) Since it is static , you can only have one of these
suckers at any one time.
One last consideration that I would like to bring into this is the
synchronization issue. It was not address in the first method, but I
included into the second one.
Hope this helps you.
Ricky Szeto
E-mail [EMAIL PROTECTED]
[EMAIL PROTECTED]
Homepage http://www.scs.ryerson.ca/~rszeto
On Thu, 7 Oct 1999, Stuart Allen wrote:
> ----------------------------------------------------
> Please read the FAQ at <http://java.apache.org/faq/>
> It does have a search feature!
>
> We cannot guess what you are trying to do:
> #1. Include version numbers for all software.
> #2. Include relevant configuration settings.
> #3. Include full descriptions of the problem.
>
> Got Linux? Seeing lots of java processes?
> <http://java.apache.org/faq/?file=274>
> ----------------------------------------------------
>
> Hello
>
> I am having a problem finding a successful way of sharing data between two
> servlets. I have tried two methods so far, both of which end up with a
> separate set of data for each servlet that access it. The first involved
> making a superclass with global static variables. Any servlet requiring
> access to this single-source data would extend this class. The second
> involved making a class containing a pointer to an instance of itself in
> the form of a private static variable. The value of this variable is then
> read by two other servlets using a public function call.
>
> Any information as to why two separate instances of the data are being
> created in both cases would be greatly appreciated.
>
> Regards,
> Stuart
>
>
> --
> --------------------------------------------------------------
> Please read the FAQ! <http://java.apache.org/faq/>
> To subscribe: [EMAIL PROTECTED]
> To unsubscribe: [EMAIL PROTECTED]
> Archives and Other: <http://java.apache.org/main/mail.html>
> Problems?: [EMAIL PROTECTED]
>
--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]