Hi,
in this example the cookie will expire when the current browser
session is ended,
but below is a snippet of code that will make the session expire every
two minutes of inactivity.
//Main Class
public void onClick(Widget sender) {
if(sender == login){
user.setUser(userField.getText());
user.setPasswd(passwdField.getText());
LoginServiceAsync loginServiceAsync =
(LoginServiceAsync)GWT.create
(LoginService.class);
ServiceDefTarget serviceDefTarget = (ServiceDefTarget)
loginServiceAsync;
serviceDefTarget.setServiceEntryPoint("login");
AsyncCallback<String> asyncCallback = new
AsyncCallback<String>() {
public void onSuccess(String result) {
if(result != null){
RootPanel.get().clear();
RootPanel.get().add(welcome);
//session expire every
two minutes of inactivity
Cookies.setCookie("session",
result, new Date
(System.currentTimeMillis() + TWO_MIN));
sessionId.setSessionId(result);
System.out.println("login
session => "+result);
}else{
Window.alert("Login Invalid !");
}
}
public void onFailure(Throwable caught) {
System.out.println(caught);
}
};//end asyncCallback
loginServiceAsync.login(user, asyncCallback);
}//end if(sender == login)
}//end onClick
//end class Main
//Class SessionServiceImpl
public SessionId session(SessionId sessionId) {
HttpSession httpSession =
getThreadLocalRequest().getSession(false);
if(httpSession != null){
try {
sessionId.setSessionId(httpSession.getId());
} catch (IllegalStateException e) {
sessionId.setSessionId("");
}
return sessionId;
}//end if(result == null)
return null;
}//end session
//end Class SessionServiceImpl
//Class LoginServiceImpl
public String login(User user) {
if(user != null && user.getUser().equalsIgnoreCase("vagner") &&
user.getPasswd().equals("Javagner")){
HttpSession httpSession =
getThreadLocalRequest().getSession();
//Specifies the time in seconds, before the
servlet container will invalidate this session.
httpSession.setMaxInactiveInterval(1000 * 60 *2);
return httpSession.getId();
}//end if
return null;
}//end login
//end LoginServiceImpl
thanks All ;-)
Professor Vagner
Vagner Araujo.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---