2012-05-07 57 views
1

繼:如何編寫JSTL而不是Scriplets來獲取用戶會話?

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

感謝

+1

http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html – jdevelop

+1

這裏是如何使用JSTL獲取會話信息的例子(http://www.coderanch.com/t/525266/JSP/java/session-value-JSP-page-JSTL) – Rachel

回答

5

應該工作:

<c:if test="${not empty sessionScope.userID}"> 
    <li><a><small>Logged in as ${sessionScope.userID}</a></li> 
</c:if> 
+0

工作就像一個魅力。謝謝 – unnamed