I’m working on GWT. In my application I want to add a session time out after 2 minutes when no action is performed (including mouse events).
I wrote a class in which I used a GWT session object.
public static boolean ValidSession(HttpSession session) {
boolean aResult = true;
logger.debug("Start of ValidSession");
try
{
if(session!=null )
{
String strUserInf="";
strUserInf=(String)session.getAttribute("userInf");
logger.debug("User Inf in session is: " + strUserInf);
if(strUserInf==null || strUserInf.trim().equals(""))
{
logger.debug("User Info blank");
aResult =false;
}
}
else
{
logger.debug("SessionNull");
aResult=false;
}
}
catch (Exception e)
{
logger.error("Exception in ValidSession: ", e);
aResult = false;
}
logger.debug("End of isSessionValid");
return aResult;
}
public static void TimeUpdate(HttpSession session){
session.setAttribute("lastAccessed", String.valueOf(session.getLastAccessed()));
System.out.println("lastAccessed "+ session.getAttribute("lastAccessed"));
}
But it resets the timer only on RPC call. I want to detect mouse movements as well.
Can anyone suggest a solution? Thanks in advance.
You can do code something like this on on module load.
Create one timer which is running every 2 minute and set session expire flage:
call this method for Renew the timer session as below in on module load using this method:
NativePreviewHandler handler catch on mouse event and check that session is expired or not flag.
if your screen stable for 2 minute than it will set expire session variable value false through timer and if value is false then do logout.
SESSION_EXPIRED is a constant variable for session expired check not more that that SessionFactory is my custom factory code. U just ignore that used varibles which my project pattern. u have to just set one constant only not more than that. Let me know if still any query.