getSession在Angular 6和Spring Boot中不起作用

时间:2019-04-24 07:42:20

标签: angular spring spring-boot

我正在研究Angular 6和Spring引导项目。 我在@RestController的春季启动中设置服务器端自定义会话

  @RequestMapping(value = "/movies",method = RequestMethod.GET)
public ResponseEntity<?> getAllMovies(  HttpServletRequest request) {
    try {
        final HttpSession session = request.getSession();
        session.setAttribute("name", "value");
        return movieMediator.getAllMovies();
    } catch (Exception e) {
        e.printStackTrace();
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

并尝试在另一个RestController中获取值,但变量'messages'为空。

 @RequestMapping(value = "/theatres",method = RequestMethod.GET)
public ResponseEntity<?> getAllTheatres(HttpServletRequest request, HttpSession session) {
    try {
        String messages = (String) request.getSession().getAttribute("name");
        System.out.println("messages//"+messages);
        return theatreMediator.getAllTheatres();
    } catch (Exception e) {
        e.printStackTrace();
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

我的应用程序包含JWT,在邮递员中,http会话可以正常工作,但是当我在浏览器中将其打开时,该值为null。你可以帮忙吗?

0 个答案:

没有答案