Forums Register Login

Can we restrict number of sessions through configuration(web.xml).

+Pie Number of slices to send: Send
Hi Everyone,

My first post and the first query. I want to know if there is anything in web.xml through which I can restrict the number of sessions.

I can only think of using the HttpSessionListener and restricting the number of sessions but I am not sure if there is any configuration tag available for web.xml to do it.

Thanks
Sanjeet
+Pie Number of slices to send: Send
Hi,
There is no entry in web.xml to restrict number of sessions in a JVM.
You need to do that programatically.
+Pie Number of slices to send: Send
 


I can only think of using the HttpSessionListener and restricting the number of sessions



How do u do it?
+Pie Number of slices to send: Send
Hi,

This

public class SessionCounter implements HttpSessionListener {
private static int sessionCount = 0;


public void sessionCreated() {
}
}
+Pie Number of slices to send: Send
Hi,

A psudo example. Something like this will let you control sessions.

public class SessionCounter implements HttpSessionListener {
private static int sessionCount = 0;


public void sessionCreated() {
if (SessionCount < 10) {
sessionCount++;
else
// forward the request to some jsp that will tell the user to wait OR some logic
}

public void sessionDestroyed() {
sessionCount--;
}
}

Do let me know if something is wrong with this.

Thanks
Sanjeet
+Pie Number of slices to send: Send
Hi Sanjeetz,

There is no way to control the number of sessions created through DD.
What r u trying to explain thru ur code?.It simply increments or decrements the sessioncount variable's value whenever session has been created or destroyed respectively.It has nothing to control the number of sessions created.Moreover sessionCreated() method is invoked only after the session is created.So u cant do it in this way.

hth..

Regards,
Priya.
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 744 times.
Similar Threads
How to restrict two user with same username and password
Restricting request threads in Tomcat
Active Sessions
limiting the number of user logging an application to a specific number
Restricting Http methods thru tomcat configurations
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:52:27.