有的業務需要知道當前登錄的用戶
當然需要引用這個啦
import javax.servlet.http.HttpServletRequest;
然后
HttpSession session = request.getSession();//import javax.servlet.http.HttpSession; UserModel user = (UserModel) session.getAttribute("USER_SESSION");//用戶類import com.hs.model.UserModel;
取出來就得了,注意,這里只能獲取用戶名,至於用戶角色
這樣做更安全,而不是吧用戶角色放在session中,不要問我怎么知道的