如何编写JSTL而不是Scriplets来获取用户会话?

tha*_*shd 1 java jsp jstl java-ee

以下:

<% if ((String) session.getAttribute("userID") != null) { 
     String username= (String) session.getAttribute("userID"); %> 
     <li><a><small>Logged in as <%=username %></a></li> 
<% } %>
Run Code Online (Sandbox Code Playgroud)

谢谢

Tom*_*icz 5

应该管用:

<c:if test="${not empty sessionScope.userID}">
  <li><a><small>Logged in as ${sessionScope.userID}</a></li>
</c:if>
Run Code Online (Sandbox Code Playgroud)