Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help needed for java to calculate number of user online

 
hafiz ijaz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need to calculate all the user who are connected to the server.and then i need to send this this total to all the users who are connected at that time.please can some body help me with java codes.i am totally new to java.
thanks in advance.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "help".
If you're really new to Java, servlets, and JSP, this project might be a bit over your head.

You might be better of starting with a good book or web tutorial that introduces the building blocks of a Java web application in an order that makes sense to someone learning from the ground up.

Once you get a feel for the environment, you'll probably be able to come up with several ways of doing this.
 
hafiz ijaz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[thanks BEN!
I did started learning.but i wanted the idea from some one who can give me some clue which class i shall use.my idea is to start with.


.i wanted to make sure i am not going wrong way.



[BSouther: Added UBB CODE tags]
[ January 09, 2008: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The approach will depend on what you mean by active user.

If you roll your own login, this is pretty easy to do.
I have a demo application on my site that does exactly what you're trying to do.
http://simple.souther.us/not-so-simple.html
Look for SessionMonitor.

Again, if you're just starting out with programming, Java, Servlets and/or JSP, this project might be a little too advanced.

In a nutshell, I bind a map to context scope that holds references to all the active sessions. When someone logs in I bind a userBean object to their session and then add their sessionId to that map. I use a SessionListener to insure that the sessions are removed from the map when they're invalidated.

Note: This approach will not work in a clustered environment as it is.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by hafiz ijaz:

I wanted to make sure i am not going wrong way.


In my opinion, using JSP for anything but a view tier would be the wrong way.
In our CodeBarn there are some very simple example apps that show how to use the Model, View, Controller (MVC) pattern in a Java web application.

The project on my site will be easier to understand if you make sure you understand MVC before looking at it.
This article by Bear Bibeault (one of the JavaRanch sheriffs) is a nice introduction to the concept.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic