确实从来没有
null。该会话 始终 存在于JSP EL中, 除非 您添加
<%@page session="false" %>
到JSP的顶部。然后,您可以按照以下方式检查会话(仅适用于EL 2.2!):
<c:if test="${pageContext.request.getSession(false) != null}"> <p>The session has been created before.</p></c:if>我不确定具体的功能要求是什么。如果您要检查会话是新建的还是已经创建的,请
HttpSession#isNew()改用。
<c:if test="${not pageContext.session['new']}"> <p>You've already visited this site before.</p></c:if><c:if test="${pageContext.session['new']}"> <p>You've just started the session with this request!</p></c:if>(括号表示法new
是强制性的,因为它new
是Java语言中的保留文字)
如果您依赖 特定的 会话属性,例如设置为的登录用户
session.setAttribute("user", user);那么您应该宁愿拦截它:
<c:if test="${not empty user}"> <p>You're still logged in.</p></c:if><c:if test="${empty user}"> <p>You're not logged in!</p></c:if>


