How do you check if a session exists for the request in EL? I’m trying something like:
<c:if test="${pageContext.request.session != null}"> ... </c:if>
but it seems like it’s never null.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s indeed never
null. The session is always present in JSP EL, unless you addto top of JSP. You could then check for the session as follows (EL 2.2 only!):
I’m not sure what’s the concrete functional requirement is. If you’d like to check if the session is new or has already been created, use
HttpSession#isNew()instead.(the brace notations for
neware mandatory becausenewis a reserved literal in Java language)Of if you’re relying on a specific session attribute, such as the logged-in user which is been set as
then you should rather be intercepting on that instead: