GWT RequestFactory中的会话处理

ngs*_*nga 1 session gwt requestfactory

有人可以向我展示一个关于使用GWT RequestFactory进行会话处理的简单示例.也许这很简单,但我无法弄清楚.

我在某处读到了我应该使用的ThreadLocal.好吧,我做到了.这是我的代码:

public class EC_RequestFactoryServlet extends RequestFactoryServlet {
private static final ThreadLocal < HttpServletRequest > uniqueReq =
    new ThreadLocal < HttpServletRequest > () {
        @Override protected HttpServletRequest initialValue() {
            return null;
        }
};

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
{
    uniqueReq.set(req);
    super.doPost(req, res);
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
    uniqueReq.set(req);
    super.doGet(req, res);
}}
Run Code Online (Sandbox Code Playgroud)

这节省了会话:

public class Authentication {
public static void SetLoggedInUserToSession(User user) {
    EC_RequestFactoryServlet.getThreadLocalRequest()
            .getSession().setAttribute("LOGGED_IN_USER", user);
}

public static User GetLoggedInUserFromSession(){
    return (User)EC_RequestFactoryServlet.getThreadLocalRequest()
            .getSession().getAttribute("LOGGED_IN_USER");
}}
Run Code Online (Sandbox Code Playgroud)

登录后,没关系,但在另一个请求之后,会话为空.

那我错过了什么?还是更好的方式?