Last active
February 26, 2018 20:27
-
-
Save darbyluv2code/66520f84c6c26e50b37ad1fca26c08da to your computer and use it in GitHub Desktop.
JSP - Loop over all scope attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%@ 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