Session objects in the server

Hi,

Im a complete beginner with JSP and I have the following question:

I have a tomcat app server. Everytime a user connects to my server for the first time a new session object is created, Am I right?

My question is: Is there any method or class that gives me access to all the session objects in my server? I mean, if two different users are connected I should have two session objects, so a way I can access them together, not independently to each user session object when he asks for a page of my server.

Thanks in advance

[558 byte] By [jjilko@hotmail.coma] at [2007-11-26 15:22:26]
# 1

> Hi,

> Im a complete beginner with JSP and I have the

> following question:

> I have a tomcat app server. Everytime a user connects

> to my server for the first time a new session object

> is created, Am I right?

Yes.

>

> My question is: Is there any method or class that

> gives me access to all the session objects in my

> server?

Nothing built in. But if you use an HttpSessionListener then you can create a List of all the sessions. You can store it in the servlet context and all users/pages would have access to the list when they need it.

You can find the API for the HttpSessionListener interface here: http://java.sun.com/j2ee/1.4/docs/api/. It is pretty simple, just two methods sessionCreated and sessionDestroyed, both of which provide access to the session (and via the session - the servlet context) being acted on. You would use the sessionCreated method to store the session in your list of all sessions, and the sessionDestroyed method to remove the session from the list when the user logs out or leaves the site.

>I mean, if two different users are connected

> I should have two session objects, so a way I can

> access them together, not independently to each user

> session object when he asks for a page of my server.

>

> Thanks in advance

stevejlukea at 2007-7-8 21:37:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

> I have a tomcat app server. Everytime a user connects

> to my server for the first time a new session object

> is created, Am I right?

Actually the answer is maybe.

In a servlet a session is not created until you call either request.getSession() or request.getSession(true)

In a JSP the seesion is created by deafult but it is possible to use the page directive attribute "session=false" to prevent a session from being created.

In Struts a session is created by default and ActionForms are stored in the session by default. Not sure if sessions can be disabled in Struts.

Not sure about JSF, velocity, Spring MVC or any of the other frameworks but I would assume they create sessions by default.

tolmanka at 2007-7-8 21:37:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...