File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes 'no. of users online' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark " Watch " New topic
Author

'no. of users online'

Bindesh V Nair
Greenhorn

Joined: Jun 16, 2004
Posts: 3
In order to create the 'no. of users online' servlet, i did the following

Implemented HttpSessionListener and in the sessionCreated(), i incremented the variable kept in the ServletContext by one. And in the sessionDestroyed() decremented it by 1

In the corresponding servlet I printed the value of the ServletContext attribute..

But it is not working..

Pls. help
Fernando Margueirat
Ranch Hand

Joined: Jun 07, 2004
Posts: 33
What do you mean by it is not working? What is it doing?

FM
Bindesh V Nair
Greenhorn

Joined: Jun 16, 2004
Posts: 3
It is not showing the no. of users online. I opened two internet explorers, then in the second browser window when i try to access the same web page the logic should work and it show the no. of users online. But it is still showing 1


Pls. help
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

Bindesh,
The servlet is working correctly. Multiple sessions of IE share a session. If you have another browser on the machine, open it and then you get a new session. Or if you close IE and reopen it, you will get a new session.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sarah Marsh
Ranch Hand

Joined: Mar 06, 2001
Posts: 282
Multiple sessions of IE share a session, is this definately true?
Bindesh V Nair
Greenhorn

Joined: Jun 16, 2004
Posts: 3
Thanks everybody !

I will try and get back ...
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476


The servlet is working correctly. Multiple sessions of IE share a session. If you have another browser on the machine, open it and then you get a new session. Or if you close IE and reopen it, you will get a new session.



I don't think this is right. Session is being generated by the server and not the browser, so browser has no control over how session is generated. I just tried it on my server and two different session ids are being generated by two sepate instances of IE.

Alex


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Eric Schumacher
Greenhorn

Joined: Jun 02, 2004
Posts: 20

Multiple sessions of IE share a session


This depends on a few things. If you open a new IE window from your existing 'session' (File>New>window) you may infact be sharing the 'session' in two windows. It may also be pssible that when you open a new instance of IE on an XP machine with low amounts of ram you are not always creating a new process...and may be sharing a 'session'....

Older versons of OS's and IE had a setting where you could force new windows to open in new sessions...but this is not the case with XP and IE6.

XP dictates whether new IE instances get a new Process. The more resources available to the system the more likely that that new window of IE will get a new process or session.

If the user creates a new session with ctrl-n they will always share the 'session' between windows as far as I can tell.
[ June 19, 2004: Message edited by: Eric Schumacher ]
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Ok, as I test I loged in to my web page and got session id 3433, then I pressed ctrl-n to launch new browser, loged in and got sesion 5644. So, obviously server is getting new request and creates new session. In my understanding mechanism that creates new session does not know what instance of IE request came from.
Eric, if you mean that by pressing ctrl-n and launching new browser I am sharing the same session, well by just starting a new browser with the same page I do not send a request to the server, and thus new session is not created, I am just display a clone of previous browser instance. As for OS, if I were running JavaScript and object was created, I see how state of OS could affect object's state, but we are dealing with server here...
But in my case I loged in, so may be the mechanism by which session id is getting assigned is a little bit different when servlet runs off the page alone.
Anybody else want to comment, may be I am wrong?

Alex
[ June 19, 2004: Message edited by: Alex Kravets ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 'no. of users online'