jsp中获取session

// 不推荐使用
<%
if(session.getAttribute("userInfo") == null) {
response.sendRedirect("./login.jsp");
}
%>

// 使用El表达式
function checkLogin() {
var uid = "${userInfo.id}"; // 需要添加引号
if (uid == 0) {
window.location.href = "./login.jsp";
}
};

// 不需要引号
${userInfo.username}

你可能感兴趣的:(jsp中获取session)