Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7406955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:38:07+00:00 2026-05-29T05:38:07+00:00

How do you check if a session exists for the request in EL? I’m

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:38:08+00:00Added an answer on May 29, 2026 at 5:38 am

    It’s indeed never null. The session is always present in JSP EL, unless you add

    <%@page session="false" %>
    

    to top of JSP. You could then check for the session as follows (EL 2.2 only!):

    <c:if test="${pageContext.request.getSession(false) != null}">
        <p>The session has been created before.</p>
    </c:if>
    

    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.

    <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>
    

    (the brace notations for new are mandatory because new is 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

    session.setAttribute("user", user);
    

    then you should rather be intercepting on that instead:

    <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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to check for the existence of the Session in a base page
I came across Django request.session ; I know how to set and test it
Trying to save the $_SESSION['uID'] within the session to use for functions like pulling
What's an elegant way in Classic ASP to check if session cookies are enabled
I want to check some things about the state of the session, the user
What is the best way to check for the existence of a session variable
Check out this test: [TestFixture] public class Quick_test { [Test] public void Test() {
check this out: template <class T> class Test: public T { public: void TestFunc()
I'm doing a simple check for some user data that get's put into session
i'm working on a custom login page in mvc.net. I check logins like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.