Reputation: 591
I want to check if the user is logged in or not using JSTL.
I tried the following code:
<c:if test="${sessionScope.logged_in == null}">
<c:redirect url="index.jsp"></c:redirect>
</c:if>
I have also tried the following code but it throws an IllegalStateException
:
<c:if test="${empty user}">
<b>you are not logged in</b>
<c:redirect url="index.jsp"></c:redirect>
</c:if>
but it is not working.
How can I implement the following code in JSTL:
<%
String logged_in = (String) session.getAttribute("logged_in");
if (logged_in == null) {
response.sendRedirect("index.jsp");
}
%>
Upvotes: 2
Views: 1386
Reputation: 11579
Try this:
<c:if test="${empty logged_in}">
<c:redirect url="index.jsp"></c:redirect>
</c:if>
Upvotes: 3