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;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@SuppressWarnings("serial")
public class SessionImpl extends RemoteServiceServlet implements
ISession {
public static HttpSession httpSession;
@Override
public String getStrAttribue(String attribute) {
httpSession = getThreadLocalRequest().getSession(true);
return (String) httpSession.getAttribute(attribute);
}
@Override
public void setAttribue(String attribute, String attValue) {
httpSession = getThreadLocalRequest().getSession(true);
httpSession.setAttribute(attribute, attValue);
}
}
To use session (on client side)
@Inject
public ISessionAsync session;
session.setAttribue("User","Sujit",new AsyncCallback<Void>() {
@Override
public void onSuccess(Void
result) {
//some event
}
@Override
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 google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment