Question

I want to find the first request which is coming to jsp. Once a window is closed, again I want to find the first request coming to jsp, but I do not want to restart my server. I am trying this:

String name=session.getAttribute("val"); 
if(name!=null)
{
//something
}
else
{
//something
} 

It is working only for the first request. After that, I have to restart the server again and again.

Moreover, I want to find the time spent on particular jsp.

Était-ce utile?

La solution

You are storing the data in Server Session. It has invalidation period (configurable, let's say 10 min for example), so it is cleared only after this period. Closing the window doesn't affect this logic at all.

Handling of window behavior should be done on client side with Javascript. Take a look at window.onload and window.onbeforeunload events.

Time spent on the page can also be captured on client side. In general the logic could be:

  1. When page loaded (onload event) you start the timer.
  2. When page is unloaded (onbeforeunload event) you save timer value to some local storage of sending it to server with ajax call.

Autres conseils

This is what you are looking for.

Try with below options:

  • web.xml

    <session-config>
        <session-timeout> 5 </session-timeout>
    </session-config> 
    
  • HttpSession.invalidate()

  • set the cache-control meta tag in the header to no cache to prevent session reuse.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top