Hi,

Thanks everyone for the reply.

Actually as it was my first application, I wasn't even using a JavaBean.
 Just one Servlet doing everything [:-(   I know! - I know!].
 Vector was my instance variable, not a class variable.

Looks like JavaBeans along with Sessions will solve my problems.

Just to make sure that I understand -

1) I should not store anything that I need between two requests in the
 Servlet instance variables (or in JSP <%! ...%> section variables), as it
could be overwritten/used by other users requests.

2) Also I should not have (or use) *ANY* instance variables in the Servlet
object,  (let alone the static class variables)
 if I want my Servlet to be thread safe, as the same object will be used for
all the requests concurrently.
 This is assuming I do not want to declare my Servlet/JSP as < ...
isThreadSafe = "false" ...>

 Similarly do I have to declare all the Application Scope JavaBean methods
as "synchronized" to make them thread safe ?

Please confirm or clarify.

Also, is there any doc which explained this in detail ?

thanks,

- Rajesh

 -----Original Message-----
From: Mike McElligott [ mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ]
Sent: Thursday, October 14, 1999 6:32 PM
To: 'Save, Rajesh (CAP, CARD)'; [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
Subject: RE: Sessions ?



Rajesh,

You want to use a bean in the session context.  So when you do your usebean,
set the scope attribute to session.  The servlet engine will check to see if
there is an instance of the class you're requesting in the session with that
id.  If there isn't, it will create one using the no-args constructor of
your javabean.  The session namespace isn't shared (that's what session is
all about) - if you set the scope to session you should be creating a new
Vector bean for each unique browser (session).

I believe the number of active servlets is left up to the implementer of the
engine.  It's not an issue you're supposed to have to worry about.

What may be happening is that you're using a bean (or storing an object)
with application scope and then referencing that on your jsp pages.  This
would cause the problem you're describing.  Alternatively, if the bean
you're instantiating relies on some shared resource (both beans refer to
another object that retains the current recordid, for instance) you might
run into the same problem as well.

Mike

-----Original Message-----
From: Save, Rajesh (CAP, CARD) [ mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ]
Sent: Thursday, October 14, 1999 3:10 PM
To: [EMAIL PROTECTED]
Subject: Sessions ?


Hi,

Can someone explain how the multiple (concurrent) requests are handled
    by the Web-server/Servlet-engine with regards to Servlet/JSP/JavaBeans ?


My environment: HP-UX, JRun 2.3.3 (Build-154) as Web server & Servlet
engine.

I have a simple application where a single Servlet is called repeatedly to
(first) query the database and
 then to display the results one record at a time. (Bad design ? well, it
was my first app.)

This Servlet makes the Database query and stores records into a Vector,
 which are then displayed (one at a time) on successive invocations
depending upon the "Next|Prev" buttons.

I would obviously like each user to be able to make his own query and see
his private results.
If I run this Servlet from one browser and then from another (browser) on
different machine,
I see the same data that is being displayed to the first user. This shows
there is only one instance of Servlet object.

I have NOT used sessions. I believe Sessions are supposed to help here. But
how ?
Do I have to create different Vector per Session-ID or one Servlet object
gets created per session ?

How does it work when I have JSP and JavaBeans ?
How many JavaBeans (objects) are created when I <jsp:useBean /> a JavaBean
at a Request/Session/Application scope ?

I haven't seen ANY talk about it in all the discussion that goes on here or
in any of the examples on the web either.
Is this a no-issue ?

Thanks,

- Rajesh

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
FAQs on JSP can be found at:
  http://java.sun.com/products/jsp/faq.html
<http://java.sun.com/products/jsp/faq.html>
  http://www.esperanto.org.nz/jsp/jspfaq.html
<http://www.esperanto.org.nz/jsp/jspfaq.html>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to