前後端分離 | 關於登入狀態那些事
阿新 • • 發佈:2018-12-14
@RequestMapping("setCookie") public String setCookie(HttpServletResponse response,String callback){ Cookie cookie = new Cookie("test","same"); cookie.setPath("/"); response.addCookie(cookie); if (StringUtils.isNotBlank(callback)){ return callback+"('success')"; } return "success"; } @RequestMapping("getCookie") public String getCookie(HttpServletRequest request,HttpServletResponse response,String callback){ Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length >0) { for (Cookie cookie : cookies) { System.out.println("name:" + cookie.getName() + "-----value:" + cookie.getValue()); } } if (StringUtils.isNotBlank(callback)){ return callback+"('success')"; } return "success"; }