request.getSession(false)未检测到上一个会话



我有三个运行tomcat的服务器7。我正在使用JDK 7和弹簧框架。

在我的开发和生产环境中,一切正常运行,但是在第三台机器上,我遇到了检测会话的问题。

在第三台服务器上,初始页面打开了正常,但以下代码返回null。

    @RequestMapping(value="/getCaptcha",method=RequestMethod.POST)
    public @ResponseBody OutputStream getCaptchaImage(HttpServletRequest request, HttpServletResponse response) throws IOException{
    String stToken = request.getParameter("token");
    OutputStream os = null;
    try{
        HttpSession httpsession = request.getSession(false);
        System.out.println("HttpSession: "+httpsession);
        if(httpsession != null){
            ...
        }
    }
    catch(Exception e){
        e.printStackTrace();
    }
    return os;
}

这里的httpsession是无效的,它无法检测我先前设置的会话

    HttpSession httpsession = request.getSession(true);

除此之外,在我的整个项目中,reques.getSession(false)即使以前设置了会话。

我不确定我是否缺少某些内容,因为同一代码在其他两个服务器上都可以完美地工作。任何帮助/指导/建议将不胜感激。

您可以简单地在Spring MVC的请求方法中声明HTTP会话

@RequestMapping("/signup")
public void handleMyRequest(HttpSession session, ...) {
   ...
}

不确定是否适合您的要求。我为我的项目做了。

最新更新