我正在研究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。你可以帮忙吗?