【发布时间】: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