【问题标题】:session is not working when deploy app engine部署应用程序引擎时会话不起作用
【发布时间】:2023-04-04 02:14:02
【问题描述】:

会话在我的本地机器上运行,但是当我部署应用程序时,会话不起作用。

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。但是会话丢失了,当用户登录时我无法获取用户名。

【问题讨论】:

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

标签: java google-app-engine gwt


【解决方案1】:

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

https://developers.google.com/appengine/docs/java/config/appconfig?csw=1#Java_appengine_web_xml_Enabling_sessions

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-02
    • 2022-11-05
    • 2015-11-22
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    相关资源
    最近更新 更多