문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top