Skip to content

Instantly share code, notes, and snippets.

@darbyluv2code
Last active February 26, 2018 20:27
Show Gist options
  • Select an option

  • Save darbyluv2code/66520f84c6c26e50b37ad1fca26c08da to your computer and use it in GitHub Desktop.

Select an option

Save darbyluv2code/66520f84c6c26e50b37ad1fca26c08da to your computer and use it in GitHub Desktop.
JSP - Loop over all scope attributes
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
</head>
<%
String s="John Doe";
pageContext.setAttribute("theStudent", s);
%>
<body>
<c:set var="data" value="${theStudent}" />
the count of ${data} is : ${fn:length(data)}
<hr>
<h3>pageScope</h3>
<table>
<c:forEach items="${pageScope}" var="p">
<tr>
<td>${p.key}</td>
<td>${p.value}</td>
</tr>
</c:forEach>
</table>
<hr>
<h3>requestScope</h3>
<table>
<c:forEach items="${requestScope}" var="p">
<tr>
<td>${p.key}</td>
<td>${p.value}</td>
</tr>
</c:forEach>
</table>
<hr>
<h3>sessionScope</h3>
<table>
<c:forEach items="${sessionScope}" var="p">
<tr>
<td>${p.key}</td>
<td>${p.value}</td>
</tr>
</c:forEach>
</table>
<hr>
<h3>applicationScope</h3>
<table>
<c:forEach items="${applicationScope}" var="p">
<tr>
<td>${p.key}</td>
<td>${p.value}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment