• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setMaxInactiveInterval

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody:
My question is... Really, in method setMaxInactiveInterval(int interval), interval are seconds, minutes, ...
API says:
"Specifies the time, in seconds, between client requests before the servlet..."
Nevertheless, I have proven to put setMaxInactiveInterval(1) and setMaxInactiveInterval(60) and in both cases the session invalidates to the minute to be created.
Another question...somebody can say me that I must make to detect if a session is invalidated to redirect users to my login page??
Thanks.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I bet $1 that you will be scolded within the next 12 hours by the "Name Police".
"your name no good"
 
Harpartap Singh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And, about detecting session invalidation, you have to use the Event listener. In this case the HttpSessionListener. Write a class that implements the <b>HttpSessionListener interface</b> and override the <b>sessionDestroyed()</b> method.
Inside the sessionDestroyed() remember to call <b>HttpSessionEvent.getSession()</b> to really tell, which session was destroyed.
http://jakarta.apache.org/tomcat/tomcat-4.0-doc/servletapi/javax/servlet/http/HttpSessionListener.html
About setMaxInactiveInterval(1) or (60) behaving the same, make sure you are setting the inactive interval on the correct session. It could be using the system default, or the <session-config> <session-timeout> elements in the web.xml.
If you still can reproduce this, please post the application server/version you are using, so someone else could reproduce it.
/hs
 
David CLh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, Harpartap, as you can see, I've changed my name. I hope this is good.
I'm using Tomcat 4.0 and in web.xml file I'm using this lines:
<web-app>
<listener>
<listener-class>
SessionCounter
</listener-class>
</listener>
</web-app>
And this is my listener class:
// ...imports...
public class SessionCounter implements HttpSessionListener, Serializable {
private static int TotalSessions = 0;
private static int ActiveSessions = 0;
public void sessionCreated(HttpSessionEvent event) {
HttpSession session = event.getSession();
TotalSessions++;
ActiveSessions++;
session.setMaxInactiveInterval(60);
// I've prove session.setMaxInactiveInterval(1); too
registerCounter(event);
}
public void sessionDestroyed(HttpSessionEvent event) {
HttpSession session = event.getSession();
ActiveSessions--;
System.out.println("Session destroyed..." + session.getId());
}
public static int getTotalSessions() {
return(totalSessions);
}
public static int getActiveSessions() {
return(ActiveSessions);
}
private synchronized void registerCounter(HttpSessionEvent event) {
HttpSession session = event.getSession();
session.setAttribute("SessionCounter", this);
}
}
I think it's correct, isn't it?
When I must to send to my users toward the login page??
Thanks.
 
Harpartap Singh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I didn't read your question carefully. You need to detect session invalidation for "redirect"ing to login page.
Well, in that case you dont' need listeners to detect invalidation.
In the servlets that you are controlling access to, each time they are accessed (in doXXX() methods), check to see if a session exists, if not, redirect them to login servlet

Just remember a gotcha regarding sessions and JSP pages (not servlets):
- if you don't have the directive <%@ page session="false" %> in your jsp page, if a session does not exist, a NEW one will be created for you automatically.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic