Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GWT-RemoteService接口和Spring-如何获取HttpSession?_Spring_Gwt_Httpsession - Fatal编程技术网

GWT-RemoteService接口和Spring-如何获取HttpSession?

GWT-RemoteService接口和Spring-如何获取HttpSession?,spring,gwt,httpsession,Spring,Gwt,Httpsession,我将GWT(2.5)与RPC、Spring和Postgresql一起用于我的项目。我的问题是关于HttpSession的处理。 到服务器的所有查询都由Spring(DispatchServlet)调度到我的GwtController(extends RemoteServiceServlet)。 特定的RemoteService被注入GwtController中。在GWTController中很容易获得HttpSession。 在示例中,通过getThreadLocalRequest().getS

我将GWT(2.5)与RPC、Spring和Postgresql一起用于我的项目。我的问题是关于HttpSession的处理。 到服务器的所有查询都由Spring(DispatchServlet)调度到我的GwtController(extends RemoteServiceServlet)。 特定的RemoteService被注入GwtController中。在GWTController中很容易获得HttpSession。 在示例中,通过getThreadLocalRequest().getSession()或仅通过request.getSession()执行。 我的问题是如何在RemoteService中获取HttpSession对象

public class GwtRpcController extends RemoteServiceServlet {
……………
private RemoteService remoteService;
private Class remoteServiceClass;
………………

public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
    …………
} 

public String processCall(String payload) throws SerializationException {
    …………
}

public void setRemoteService(RemoteService remoteService) {
    …………….
}

}
我的接口-实现RemoteService的DataService

public class DataServiceImpl implements DataService {

public Data getData(){

    !!!!! Here I want to get HttpSession !!!!!
    …………………………

}

}

您可以在
Servlet
中维护
ThreadLocal
,并将当前的
请求存储在那里,然后使用静态方法公开
请求

公共类GwtRpcController扩展RemoteServiceServlet{
静态线程本地perthread请求=
新ThreadLocal();
@凌驾
公共字符串processCall(字符串负载)引发序列化异常{
试一试{
perThreadRequest.set(getThreadLocalRequest());
返回super.processCall(有效负载);
}最后{
perThreadRequest.set(null);
}
}
公共静态HttpServletRequest getRequest(){
返回perThreadRequest.get();
}
}
公共类DataServiceImpl实现DataService{
公共数据getData(){
HttpServletRequest=gwtrpcc控制器.getRequest();
HttpSession session=request.getSession();
}
}