有办法能获取到HttpSession对象么?
我是想在登录之前设置一个属性,然后在登录后进入主页面的init方法里获得。userSession在登录前和登录后不是一个对象,没法用。。。
试一下下面的代码:
private HttpSession getHttpSession() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
return request.getSession();
} else {
return null;
}
}
在登录页面的
@Override
protected void doLogin(Credentials credentials) throws LoginException
方法中未登录时调用
RequestContextHolder.getRequestAttributes();返回null
具体是哪个类?
LoginScreen,我在主screen的init里面一样也是null
我其实就是在登录之前调用了第三方的接口获得了一些数据,我想把他传入主界面里面用于显示
可以了,需要在WEB.XML里加入:
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>