Java 部署应用程序引擎时会话不工作

Java 部署应用程序引擎时会话不工作,java,google-app-engine,gwt,Java,Google App Engine,Gwt,会话在我的本地计算机上工作,但当我部署应用程序时,会话不工作 protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String UserName = req.getParameter("username"); HttpSession request = req.getSession(); reques

会话在我的本地计算机上工作,但当我部署应用程序时,会话不工作

protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException 
{
     String UserName = req.getParameter("username");
     HttpSession request = req.getSession();
     request.setAttribute("UserName", UserName);
     request.setAttribute("Reload", "true");
     res.setHeader("Content-Type", "text/html");
     //http://demoapp04071992.appspot.com/
     //res.sendRedirect("http://127.0.0.1:8888/FileSharingDemo.html?gwt.codesvr=127.0.0.1:9997");
     res.sendRedirect("http://demoapp04071992.appspot.com/FileSharingDemo.html");
}

在本地运行时,我使用url 127.0.0.1。部署时,我使用url demoapp04071992。但是会话丢失,用户登录时我无法获取用户名。

在GAE中,您必须激活会话支持,默认情况下它未启用。以下是官方链接:


您确定您在请求中收到了
用户名
参数吗?此外,在发送重定向时,应该使用
HttpServletRequest#getContextPath
自动附加应用程序的上下文,因此不需要硬编码
http://demoapp04071992.appspot.com/
(或后面的任何URL),并将其与所需的URL连接起来,例如
“FileSharingDemo.html”