I want to get the session attribute in a GWT application. I get a session like this
HttpServletRequest request = this.getThreadLocalRequest();
System.out.println("Check HttpServletRequest");
HttpSession session = request.getSession();
but this.getThreadLocalRequest()always null.
THE CODE:
Customer:
@RemoteServiceRelativePath("service.s3gwt")
public interface getAttributeSession extends RemoteService
{
String getSessionAttribute(String name);
}
public interface getAttributeSessionAsync
{
void getSessionAttribute(String name, AsyncCallback<String> callback);
}
Server:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import daTotNghiep.client.service.getAttributeSession;
public class getAttributeSessionImpl extends RemoteServiceServlet implements getAttributeSession
{
private static final long serialVersionUID = 1L;
public String getSessionAttribute(String name)
{
HttpServletRequest request = this.getThreadLocalRequest();
System.out.println("Check HttpServletRequest");
if(request == null) System.out.println("SO BAD");
return "";
}
}
When the method is called getSessionAttribute(), I see that it this.getThreadLocalRequest()always returns null. So why? And how to fix it?
source
share