Gwt HttpServletRequest=this.getThreadLocalRequest()返回null?

Gwt HttpServletRequest=this.getThreadLocalRequest()返回null?,gwt,Gwt,我想在GWT应用程序中获取会话的属性。我得到这样的治疗 HttpServletRequest=this.getThreadLocalRequest(); System.out.println(“检查HttpServletRequest”); HttpSession session=request.getSession(); 但是this.getThreadLocalRequest()总是null 代码: 客户: @RemoteServiceRelativePath(“service.s3gwt

我想在GWT应用程序中获取会话的属性。我得到这样的治疗

HttpServletRequest=this.getThreadLocalRequest();
System.out.println(“检查HttpServletRequest”);
HttpSession session=request.getSession();
但是
this.getThreadLocalRequest()
总是
null

代码:

客户:

@RemoteServiceRelativePath(“service.s3gwt”)
公共接口getAttributeSession扩展了RemoteService
{
字符串getSessionAttribute(字符串名称);
}
公共接口getAttributeSessionAsync
{
void getSessionAttribute(字符串名称,异步回调);
}
服务器:

import javax.servlet.http.HttpServletRequest;
导入javax.servlet.http.HttpSession;
导入com.google.gwt.user.server.rpc.RemoteServiceServlet;
导入daTotNghiep.client.service.getAttributeSession;
公共类getAttributeSessionImpl扩展RemoteServiceServlet实现getAttributeSession
{
私有静态最终长serialVersionUID=1L;
公共字符串getSessionAttribute(字符串名称)
{
//TODO自动生成的方法存根
HttpServletRequest=this.getThreadLocalRequest();
System.out.println(“检查HttpServletRequest”);
if(request==null)System.out.println(“非常糟糕”);
//HttpSession session=request.getSession();
//System.out.println(“ID session”+session.getId());
返回“”;
}
}

当调用方法
getSessionAttribute()
时,我看到
this.getThreadLocalRequest()
总是返回
null
。那为什么呢?如何修复它?

方法
getThreadLocalRequest()
在类
AbstractRemoteServiceServlet
中实现,该类由
RemoteServiceServlet
继承。实现仅为方法
doPost()
设置字段
perThreadRequest
(由
getThreadLocalRequest()
使用)。这意味着,
getThreadLocalRequest()
仅当从POST请求中调用请求时才会返回该请求,并且仅当您没有在不调用super方法的情况下覆盖
doPost()
时才会返回该请求

因此,要确保
getThreadLocalRequest()
不会返回
null

  • 确保您是从POST请求(而不是GET或其他HTTP请求类型)中调用它
  • 确保未调用
    super.doPost()
    而未覆盖
    doPost()

你解决了这个问题吗?我只是在仔细研究一下,想指出
doPost()
AbstractRemoteServiceServlet
中的最终版本。所以它不能被覆盖。