Example - Dumping EL Implicit Objects

This section provides a tutorial example to dump contents of all EL (Expression Language) implicit objects using JSTL Core library c:forEach tags.

In my first JSTL Core Library example, JstlObjects.jsp, I am going to use c:forEach to browse through all implicit objects provided in the EL expression environment, and c:forTekons to break the class path into multiple items.

<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
   xmlns:c="http://java.sun.com/jsp/jstl/core" version="2.1"> 
<!-- JstlObjects.jspx
 - Copyright (c) 2012, HerongYang.com, All Rights Reserved.
-->
<jsp:directive.page contentType="text/html"/>
<html><body>
<p>Browsing all EL implicit objects:</p>
<p>"pageContext":</p>
<c:out value="${pageContext}"/><br/>

<p>"pageScope":</p>
<c:forEach items="${pageScope}" var="entry">
 <c:out value="${entry.key} = ${entry.value}"/><br/>
</c:forEach>

<p>"requestScope":</p>
<c:forEach items="${requestScope}" var="entry">
 <c:out value="${entry.key} = ${entry.value}"/><br/>
</c:forEach>

<p>"sessionScope":</p>
<c:forEach items="${sessionScope}" var="entry">
 <c:out value="${entry.key} = ${entry.value}"/><br/>
</c:forEach>

<p>"applicationScope":</p>
<c:forEach items="${applicationScope}" var="entry">
 <c:out value="${entry.key} = ${entry.value}"/><br/>
</c:forEach>

<p>"param":</p>
<c:forEach items="${param}" var="entry">
 <c:out value="${entry.key} = ${entry.value}"/><br/>
</c:forEach>

<p>"paramValues":</p>
<c:forEach items="${paramValues}" var="entry">
 <c:out value="${entry.key} = ${entry.value}"/><br/>
</c:forEach>

<p>"header":</p>
<c:forEach items="${header}" var="entry">
 <c:out value="${entry.key} = ${entry.value}"/><br/>
</c:forEach>

<p>"headerValues":</p>
<c:forEach items="${headerValues}" var="entry">
 <c:out value="${entry.key} = ${entry.value}"/><br/>
</c:forEach>

<p>"cookie":</p>
<c:forEach items="${cookie}" var="entry">
 <c:out value="${entry.key} = ${entry.value}"/><br/>
</c:forEach>

<p>"initParam":</p>
<c:forEach items="${initParam}" var="entry">
 <c:out value="${entry.key} = ${entry.value}"/><br/>
</c:forEach>

<p>Class path list:</p>
<c:forTokens
 items="${applicationScope['org.apache.catalina.jsp_classpath']}"
 delims=";" var="entry">
 <c:out value="${entry}"/><br/>
</c:forTokens>

</body></html>
</jsp:root>

Here is the output of JstlObjects.jspx running on my Tomcat 7 server as http://localhost:8080/JstlObjects.jspx?name=Herong&lang=JSP&lang=Java:

Browsing all EL implicit objects:

"pageContext":
org.apache.jasper.runtime.PageContextImpl@38763e

"pageScope":
javax.servlet.jsp.jspResponse = org.apache.catalina.connector.Respo...
javax.servlet.jsp.jspConfig = org.apache.catalina.core.StandardWrap...
javax.servlet.jsp.jspPageContext = org.apache.jasper.runtime.PageCo...
javax.servlet.jsp.jspRequest = org.apache.catalina.connector.Reques...
javax.servlet.jsp.jspSession = org.apache.catalina.session.Standard...
javax.servlet.jsp.jspApplication = org.apache.catalina.core.Applica...
javax.servlet.jsp.jspPage = org.apache.jsp.JstlObjects_jspx@1ee8942
javax.servlet.jsp.el.ImplicitObjectELResolver$ScopeManager = javax....
javax.servlet.jsp.jspOut = org.apache.jasper.runtime.JspWriterImpl@...

"requestScope":

"sessionScope":

"applicationScope":
org.apache.catalina.jsp_classpath = /C:/local/apache-tomcat-7.0.32/...
org.apache.tomcat.InstanceManager = org.apache.catalina.core.Defaul...
org.apache.tomcat.util.scan.MergedWebXml = 
   <?xml version="1.0" encoding="UTF-8"?> 
   <web-app xmlns="http://java.sun.com/xml/ns/javaee" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...>
   <display-name>Welcome to Tomcat</display-name> 
   ... configuration XML ...
   </web-app>
javax.servlet.context.tempdir = C:\local\apache-tomcat-7.0.32\work\...
org.apache.catalina.resources = org.apache.naming.resources.ProxyDi...
org.apache.jasper.compiler.TldLocationsCache = org.apache.jasper.co...
org.apache.jasper.runtime.JspApplicationContextImpl = org.apache.ja...
org.apache.tomcat.JarScanner = org.apache.tomcat.util.scan.Standard...

"param":
name = Herong
lang = JSP

"paramValues":
name = [Ljava.lang.String;@6a0cb
lang = [Ljava.lang.String;@12678ab

"header":
cookie = JSESSIONID=C82125AAD32D2F7A00AC9D73AE4C0FDC
connection = keep-alive
accept-language = en-us,en;q=0.5
host = localhost:8080
accept = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;...
user-agent = Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 ...
dnt = 1
accept-encoding = gzip, deflate
accept-charset = ISO-8859-1,utf-8;q=0.7,*;q=0.7

"headerValues":
cookie = [Ljava.lang.String;@bc5c96
connection = [Ljava.lang.String;@62867c
accept-language = [Ljava.lang.String;@6b653f
host = [Ljava.lang.String;@c449e3
accept = [Ljava.lang.String;@cee6e3
user-agent = [Ljava.lang.String;@1985d31
dnt = [Ljava.lang.String;@e61b6
accept-encoding = [Ljava.lang.String;@310d66
accept-charset = [Ljava.lang.String;@66cba4

"cookie":
JSESSIONID = javax.servlet.http.Cookie@c3b8b6

"initParam":

Class path list:
/C:/local/apache-tomcat-7.0.32/webapps/ROOT/WEB-INF/classes/
/C:/local/apache-tomcat-7.0.32/webapps/ROOT/WEB-INF/lib
   /javax.servlet.jsp.jstl-1.2.1.jar
/C:/local/apache-tomcat-7.0.32/webapps/ROOT/WEB-INF/lib
   /javax.servlet.jsp.jstl-api-1.2.1.jar
/C:/local/apache-tomcat-7.0.32/lib/
/C:/local/apache-tomcat-7.0.32/lib/annotations-api.jar
/C:/local/apache-tomcat-7.0.32/lib/catalina-ant.jar
/C:/local/apache-tomcat-7.0.32/lib/catalina-ha.jar
/C:/local/apache-tomcat-7.0.32/lib/catalina-tribes.jar
...
/C:/Program Files/Java/jre7/lib/ext/access-bridge.jar
/C:/Program Files/Java/jre7/lib/ext/dnsns.jar
/C:/Program Files/Java/jre7/lib/ext/jaccess.jar
/C:/Program Files/Java/jre7/lib/ext/localedata.jar
/C:/Program Files/Java/jre7/lib/ext/sunec.jar
/C:/Program Files/Java/jre7/lib/ext/sunjce_provider.jar
/C:/Program Files/Java/jre7/lib/ext/sunmscapi.jar
/C:/Program Files/Java/jre7/lib/ext/sunpkcs11.jar
/C:/Program Files/Java/jre7/lib/ext/zipfs.jar

Last update: 2012.

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 7 Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

 JavaBean Objects and "useBean" Action Elements

 Managing HTTP Response Header Lines

 Non-ASCII Characters Support in JSP Pages

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

JSTL Core Library

 What Is JSTL Core Library?

 c:out Action Tag

 c:out Action Tag with EL Expressions

 c:set Action Tag

 c:if Action Tag

 c:choose Action Tag

 c:forEach Action Tag

 c:forTokens Action Tag

Example - Dumping EL Implicit Objects

 Example - Calculating Prime Numbers

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Outdated Tutorials

 References

 PDF Printing Version