My database access is all working fine.
 
I just do not understand how to actually have multiple instances of a bean accross multiple sessions.  I was kinda hoping that JSP & Beans would magically handle sessions (which it sort of does - a unique cookie is given to each Browser on each PC).
 
Say, as an example, I have a Bean with the following Methods:
 
(void) processRequest(HttpServletRequest request)
    This method does the database work
 
(void) setCustomerIDNumber(int IDNumber)
    Allows the JSP page set the Customer ID Number
 
(String) getCustomerFirstName()
    Allows the JSP page get the Customer's first name
 
So with the above Bean the JSP page could give (say through a FORM textbox or hidden field) the Bean the Customer's ID number and then get the Customers FirstName & display it within the page.
 
Now here's my problem:
 
If one JSP page - on one Browsers Window on one PC sets the Customers ID number
 
    and then
 
two Browsers - on two different PC's display the Customer First Name via. the Bean then both Browsers will display the First Name based on the ID number given by one Browser on one PC.
 
I do not actually have any unique sessions.  It seems that there is only one Bean and all JSP pages - viewed in different browsers on different PCs share the contents of that one bean.
 
Do I have to include Session Handling code in the Bean to allow for multiple sessions?
 
 
 
Thanks for any help as I cannot find information of this in any JSP documentation.
 
 
 
The demo Beans which come with the JSP download from SUN (such as the DummyCart Bean) do not have any session handling code (and, in fact, the situation I am describing above also happens with the DummyCart Bean).
 
I see that a lot of users on the JSP-INTEREST mailing list seem to use Servlets and their output looks like a Bean to the JSP code.  I would rather the JSP Page <-- --> Bean module over calling Servlets directly.
 
Derek :)
 
 
----- Original Message -----
Sent: Monday, August 09, 1999 12:55 PM
Subject: RE: Session Problems (cont)

Dear Derek,

 

It seems to me that the solution is to use a db connection pool and to assign each session a seperate connection (or using one session using different queries for different sessions), this means that your bean can't be singleton, but has to have a seperate instance for each session.

the other solution i have in mind looks to me a lot worse, using the session object as a key in the set/set/is methods of the singleton. and cache values inside the singletone according to he session

 

lee

-----Original Message-----
From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]]On Behalf Of Derek Conniffe
Sent: Monday, August 09, 1999 11:06 AM
To: [EMAIL PROTECTED]
Subject: Session Problems (cont)

Hi Everyone,

 

I'm having Session handling problems.

 

I have now built a number of Beans which look after database access.  The Beans do all the database interactions within the "processRequest" public method & then there are a number of "set", "get" and "is" methods which the JSP pages use to set (via. A HREF's & FORM METHODS) and get data for display.

 

The "processRequest" public method loads up the [database] results into private class variables which are shared by all the public methods. 

 

My problem is that after the "processRequest" method is executed all sessions (Browsers ON DIFFERENT Computers) retrieve the same data from the "get" methods of the Bean.  There appears to only be one instance of a Bean at any one time & data seems to be shared accross all users.

 

With Servlets it is up to the programmer to utilise the "request.getSession(true)" method to track & control sessions.  Is this still the case with JSP/Bean programming?  If so how do you hold data (other than private class variables) for retriving by individual sessions? 

 

I think the above must be incorrect as it is only the "processRequest" public method in the Bean that has access to the "request" object (passed into processRequest as an argument).

 

This is a terrible pain in my side as I now have a site, with multiple beans, handling all database access via a singleton class & everything is working perfectly except for Session handling.  This means that right now the site is unusable.

 

I know the answer is out there somewhere :)

 

 

Derek Conniffe

 

 

 

Reply via email to