【发布时间】:2015-04-19 16:53:53
【问题描述】:
我无法获取已放入会话的值。 我想用拦截器检查这个值,但我只得到一个空值。
这是我放置变量“trustedUser”的地方
@RequestMapping(value = "/context/{token}", method = { RequestMethod.GET })
public @ResponseBody
ResponseEntity<ContexteUI> getContextByToken(@PathVariable("token") String token, HttpSession session)
throws ContextFault_Exception {
HttpStatus httpStatus = HttpStatus.OK;
if (validation(token)){
session.setAttribute("trustedUser","trustedUser");
} else {
httpStatus = HttpStatus.BAD_REQUEST;
}
return new ResponseEntity<ContexteUI>(contexte, httpStatus);
}
这是我的拦截器:
public class AuthentificationInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
System.out.println("Pre-handle");
String trustedUserTest = (String) request.getSession().getAttribute("trustedUser");
System.out.println("trustedUserTest: "+ trustedUserTest); // I only get null here, why ?
return true;
}
}
我哪里做错了?
【问题讨论】:
-
你试过了吗 getContextByToken(@PathVariable("token") String token, HttpServletRequest request) {HttpSession session = request.getSession(); session.setAttribute("trustedUser",trustedUser);
标签: spring session controller