Wednesday, February 29, 2012

Re: Session Tracking

Write a service on Server side which extends RemoteServiceServlet.
Create an object of type HttpSession as a member.
Write methods to serAttribute and getAttribute.

On client side. Inject the service and call setAttribute and
getAttribute methods wherever you want to add data to session or read
data from session.

Refer sample code below:

SessionService ( On server side)

import java.awt.List;

import javax.servlet.http.HttpSession;


public class SessionImpl extends RemoteServiceServlet implements
ISession {

       public static HttpSession httpSession;

       public String getStrAttribue(String attribute) {
              httpSession = getThreadLocalRequest().getSession(true);
              return  (String) httpSession.getAttribute(attribute);

       public void setAttribue(String attribute, String attValue) {
              httpSession = getThreadLocalRequest().getSession(true);
              httpSession.setAttribute(attribute, attValue);



To use session (on client side)

       public ISessionAsync session;

session.setAttribue("User","Sujit",new  AsyncCallback<Void>() {

                                         public void onSuccess(Void
result) {
                                                //some event

                                         public void
onFailure(Throwable caught) {
                                                // TODO Auto-generated
method stub


You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment