我想检查用户是否已使用 JSTL 登录。
我尝试了以下代码:
<c:if test="${sessionScope.logged_in == null}">
<c:redirect url="index.jsp"></c:redirect>
</c:if>
我还尝试了以下代码,但它抛出 IllegalStateException
:
<c:if test="${empty user}">
<b>you are not logged in</b>
<c:redirect url="index.jsp"></c:redirect>
</c:if>
但它不起作用。
如何在 JSTL 中实现以下代码:
<%
String logged_in = (String) session.getAttribute("logged_in");
if (logged_in == null) {
response.sendRedirect("index.jsp");
}
%>
最佳答案
试试这个:
<c:if test="${empty logged_in}">
<c:redirect url="index.jsp"></c:redirect>
</c:if>
关于java - 如何使用 JSTL 检查 session 中是否存在登录用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14764939/