1. 程式人生 > >Java在非servlet的類中獲取session的方法

Java在非servlet的類中獲取session的方法

ServletRequestAttributes servletReqAttr = 
			(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
	HttpServletRequest request = servletReqAttr.getRequest();
	HttpSession session = request.getSession();

這是在Spring MVC的專案中