我想在 GWT 应用程序中获取会话属性。我得到这样的会话
HttpServletRequest request = this.getThreadLocalRequest();
System.out.println("Check HttpServletRequest");
HttpSession session = request.getSession();
但this.getThreadLocalRequest()
总是null
。
代码 :
客户:
@RemoteServiceRelativePath("service.s3gwt")
public interface getAttributeSession extends RemoteService
{
String getSessionAttribute(String name);
}
public interface getAttributeSessionAsync
{
void getSessionAttribute(String name, AsyncCallback<String> callback);
}
服务器:
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)
{
// TODO Auto-generated method stub
HttpServletRequest request = this.getThreadLocalRequest();
System.out.println("Check HttpServletRequest");
if(request == null) System.out.println("SO BAD");
// HttpSession session = request.getSession();
// System.out.println("ID session "+session.getId());
return "";
}
}
当调用方法时getSessionAttribute()
,我看到它this.getThreadLocalRequest()
总是返回null
。所以为什么?以及如何解决?