0
<%
    Boolean loggedIn = (Boolean)session.getAttribute("login");
    System.out.println("loggedIn is " + loggedIn);
%>

<header>
    <% System.out.println("loggedIn is now " + loggedIn); %>
    <c:choose>
        <c:when test="${loggedIn}">
            <a href="#"> My Profile </a>
        </c:when>
        <c:otherwise>
            <a href="#"> Sign In </a>
        </c:otherwise>   
    </c:choose>
</header>

This is a JSPF for a project that I have made. The output for the following is

loggedIn is true
loggedIn is now true 

Despite this, my actual page always shows "Sign in" and never shows "My Profile". Also, when I change the condition to

<c:when test="${not loggedIn}">

It begins to display "My Profile". I do not get how loggedIn can be true and yet fail this statement.

Thankyou.

Arvind
  • 155
  • 3
  • 12
  • 2
    Stop using scriptlets. Really, just stop. They're a thing from the very old past. The JSP EL uses **attributes** of the page, request, session or application. Not local scriptlet variables. So it should simply be `test="${login}"` (or `test="${sessionScope.login}"`), since that's how your **attribute** is named. – JB Nizet Oct 20 '18 at 07:15
  • @JBNizet yeah this worked. I've just started using JSP and didn't know that scriptlets were frowned upon until now. Thanks for the answer. – Arvind Oct 20 '18 at 07:59

0 Answers0