• 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

Session Timeout

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a session time out configured in the web.xml.In my filter I use request.getSession(false).Then I check the value in my session object.But even after the session has expired my session object does not get a null value.



Can you tell me how to check if my session has expired?
 
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you set the session timeout in web.xml? Can give the snippet?
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
session.getSession(false) will return pre-existing session. It returns null only when there is no session associated with.

we have some methods like

getCreationTime()
getLastAccessedTime()
invalidate();

by using getLastAccessedTime() we get some time in milliseconds

and if it exceeds the time you have mentioned(<session-timeout> in web.xml(that represents hours) call invalidate() so that the session will be destroyed.


hope this works.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sure you session is not expired.You can try setting a session listner for tracking whether session has really expired or not.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jetendra Ivaturi:
(<session-timeout> in web.xml(that represents hours)



The
<session-config>
<session-timeout>?</session-timeout>
</session-config>

Is actually minutes.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Here I am facing one problem. I am checking session validity

1: if (! request.isRequestedSessionIdValid())
return mapping.findForward("invalidSession");

2: user = (User)request.getSession().getAttribute("user");
if (user == null){
// throw exception if it is null;
throw new ApplicationException("User session unavailable");
}

Problem: In line i get true for request.isRequestedSessionIdValid() but when i am trying to get value from session(ie line 2) it is giving "User session unavailable")?

Can you pls suggest where went wrong?

Thanks.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello kora,

You are checked for session availability and session is available. But you try to get session with attribute "user". Please check session with user attribute are available in your session. otherwise check whether you set your session.
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic