Thank you David, for your help! :-)

Best regards,
Lyubomir.


----- Original Message -----
From: "David Mossakowski" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, December 06, 2002 9:22 PM
Subject: Re: Multiple Thread Servlet questin


> See below
>
> Lyubomir Pashov wrote:
> > Hello,
> > I am new to Servlets.
> > Excuse me if such a question was been already answered before, but when
I searcher the archives, the error "A configuration error was detected in
the CGI script; the SEARCH-HELP template could not be found." has occurred.
> >
> > So, I need to understand do I need (and if "yes" - then how) to create
new instance of my Servlet, each separated in new Thread for evrey new
connected client?
> >
> > First I thought that this is done by default, and maybe a new copy of
the servlet is created for each client... But I found out, that if a field
is created , which increments its value into the doPost(...) /or doGet(...)/
method, its value grows up consecutively, no matter which client does its
doPost method. It behaves as a static field...
> >
> That's what threads do.  There are multiple threads of execution going
> through doGet and doPost depending on the request and all of them share
> the class variables.
>
>
> > Is there a method which to force the Servlet to create new fields
instances for each client, or this is not needed (and I am on a wrong way)?
> >
> Yes, it's called HttpSession.  You should be putting stuff that
> describes the client request in it.
>
> Create an object that will hold things for a client:
> class User{
> int visits;
> String name;
> }
>
> Create or get an existing session like this:
>
> HttpSession session = request.getSession(true);
>
> Check if it already has the user object and if it doesn't put it there:
>
> User user = (User)session.getAttribute("userObject");
>
> if (user == null)
>         session.putAttribute("userObject",user);
>
>
> At this point you have a user object that's associated with one client.
>
> you can do
>
> user.visits++;
>
> and then display the number of visits.
>
>
> > Thanks,
> > Lyubomir.
>
> Good luck,
> d.
>
> >
> >
___________________________________________________________________________
> > 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
> >
> >
> >
>
>
>
> --
> David Mossakowski
> Instinet Corporation
>
>
>
>
****************************************************************************
***
> <<Disclaimer>>
>
> This message is intended only for the use of the Addressee and
> may contain information that is PRIVILEGED and/or
> CONFIDENTIAL or both.
>
> This email is intended only for the personal and confidential use
> of the recipient(s) named above.
>
> If the reader of this email is not an intended recipient, you have
> received this email in error and any review, dissemination,
> distribution or copying is strictly prohibited.
>
> If you have received this email in error, please notify the sender
> immediately by return mail and permanently deleting the copy
> you received.
>
> Thank you.
>
>
****************************************************************************
***
>
>
___________________________________________________________________________
> 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
>
>

___________________________________________________________________________
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