Hi all,
I'm having trouble with what should be a simple feature: sharing a static variable
between two instances of the same servlet class.
Take the following example to demonstrate the problem...
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyCounter extends HttpServlet
{
private int counter = 0;
static int globalCounter = 0;
public void doGet(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><BODY>");
out.println("Count ="+(counter++)+"<br>Global count = "+(globalCounter++));
out.println("</BODY></HTML>");
}
}
>From here I configured the Servlet Attibutes twice with distinct names, but both
>pointing to the same class. I then configured two virtual paths for each of these
>servlets. However, they then run independently of each other: i.e. as though each
>servlet were running in a seperate JVM? The static counter behaves just as though it
>were not static. Is this the correct way to get two servlets to run from the same
>class?
FYI: I'm using Netscape Enterprise Server 4 SP1.
Thanks in advance.
David Finch.
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
Premiere Technologies (UK)
**********************************************************************
___________________________________________________________________________
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