升級chrome瀏覽器導致網站登錄功能不能用


筆者開發一個java web項目,低版本的chrome(74以下)可以正常登錄,升級到chrome74不能正常登錄,登錄成功后url會攜帶一個jsessionid=xxxxxx。

登錄成功那個頁面有session,可以通過session.getAttribute獲取屬性值。其他頁面就沒有session了。

如果把復制到訪問頁面后面。例如 http://localhost/111.jsp?jsessionid=xxxxxx也能正常訪問。可是tomcat給我的ssession會話憑證的

cookie是JSESSIONID,和jessionid根本就不是一回事。

在老外網站看到有人討論,說chrome72,問題類似。沒有降到72測試。直接升級到chrome76解決問題了。

症狀圖片

 

/toMyProfile.do;jsessionid=DE15789BF54EC8750DB5394BD8A99FA3

經筆者測試,上述問題消失,偶爾間又恢復。

最終解決辦法:

欺騙瀏覽器,手工添加JSESSIONID

 

 

    /**
     * 登錄
     * @param user
     * @param model
     * @return
     */
    @RequestMapping(value = "login.do",method = RequestMethod.POST)
    public String login(User user, Model model, HttpSession session, HttpServletResponse response){
        Map<String,Object> map = loginService.login(user);
        if(map.get("status").equals("yes")){

            Integer uid = (Integer) map.get("uid");
            String headUrl = (String) map.get("headUrl");

            session.setAttribute("uid",uid);
            session.setAttribute("headUrl",headUrl);

            String sessionId = session.getId();
            Cookie cookie = new Cookie("JSESSIONID", sessionId);
            cookie.setMaxAge(Integer.MAX_VALUE);
            response.addCookie(cookie);

            return "redirect:toMyProfile.do";
        }else {
            model.addAttribute("email",user.getEmail());
            model.addAttribute("error",map.get("error"));
            return "login";
        }
    }

參考來源:jsessionid所引起的問題 和解決


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM