1

I've got the following code I am trying to switch from scriptlet:

    <% if (session.getAttribute("korisnik") == null) { %>
    <a href='login.jsp'>Ulogujte se</a>
    <a href='registracija.jsp'>Registrujte se</a>
    <% } %>

to el:

    <c:if test="${sessionScope.korisnik == null}">
    <a href='login.jsp'>Ulogujte se2</a>
    <a href='registracija.jsp'>Registrujte se2</a>
    </c:if>

The scriptlet code works (hides the login and register pages if user is logged in aka has data in session) but I heard that it's bad practice so am trying to switch it to EL, but the EL part doesn't work, and I tried countless variations (just korisnik, with session scope, comparing to 0 etc).

I'm sure I'm missing something incredibly obvious here, any help would be appreciated.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Drvo Foka
  • 47
  • 9
  • 1
    Yes, in the end it wasn't the code itself that was the problem, it was something about the jstl jar I had placed. I downloaded a fresh 1.2 one and that did the job. – Drvo Foka Sep 20 '20 at 23:42

1 Answers1

1

Remember to import the taglib like so:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

Then this should work:

<c:if test="${sessionScope.korisnik == null}">
  <a href='login.jsp'>Ulogujte se2</a>
  <a href='registracija.jsp'>Registrujte se2</a>
</c:if>

Make sure the taglib is above the <html> tag

Spectric
  • 30,714
  • 6
  • 20
  • 43