1 设置session
(退出)
public abstract class WebContextUtils {
public static HttpSession getNewSession(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
//原有的Locale
RequestContext requestContext = new RequestContext(request);
Locale locale = requestContext.getLocale();
if (session != null) {
session.invalidate();
}
session = request.getSession(true);
//恢复Locale
LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
localeResolver.setLocale(request, response, locale);
return session;
}
}
2.退出相关 Controller层
@RequestMapping(value = "/logon/out")
public ModelAndView out(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mav = new ModelAndView();
request.getSession().removeAttribute("user");
request.getSession().removeAttribute(BaseWebConstants.LOGIN_USER_ID);
RequestContext requestContext = new RequestContext(request);
String local = (String) requestContext.getLocale().toString();
WebContextUtils.getNewSession(request, response);
mav.addObject("local", local);
mav.setViewName("logon/login.jsp");
return mav;
}