JSP Tutorials - Herong's Tutorial Examples - v5.11, by Herong Yang
JSTL Example - Loop Tag on Map Objects
This section provides a tutorial example on how to use a c:forEach JSTL tag to loop through entries in a java.util.Map object.
With both JSTL 1.2 API JAR and implementation JAR files installed, I visit the JstlReqParam.jspx JSP page again with IE at: http://localhost:8080/JstlReqParam.jspx?name=herong&lang=JSP.
No Java exceptions this time. The JSP page returns 2 parameters that are provided in the URL:
List of Request Parameters: name=[Ljava.lang.String;@182dd60 lang=[Ljava.lang.String;@93fa9d
But the ${entry} EL expression output is not perfect. This is because:
Based on the above understanding, I have revised my "loop" tag example to JstlReqParamRevised.jspx:
<?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.3"> <!-- JstlReqParamRevised.jspx - Copyright (c) 2006 HerongYang.com. All Rights Reserved. --> <jsp:directive.page contentType="text/html"/> <html><body> <p>List of Request Parameters:</p> <c:forEach items="${pageContext.request.parameterMap}" var="entry"> ${entry.key} = <c:forEach items="${entry.value}" var="value"> ${value}, </c:forEach> <br/> </c:forEach> </body></html> </jsp:root>
Save JstlReqParamRevised.jspx to \local\tomcat\webapps\ROOT, and run IE with URL: http://localhost:8080/JstlReqParam.jspx?name=herong&lang=JSP&lang=Java.
I am getting much better output now:
List of Request Parameters: name = Herong, lang = JSP, Java,
I think this example is a good demonstration of how JSTL technology can be used together with EL technology to develop dynamic JSP pages without using Java scripting elements.
Table of Contents
JSP (JavaServer Pages) Overview
Tomcat Installation on Windows Systems
Syntax of JSP Pages and JSP Documents
JavaBean Objects and "useBean" Action Elements
Managing HTTP Response Header Lines
Non-ASCII Characters Support in JSP Pages
►Overview of JSTL (JSP Standard Tag Libraries)
Installing GlassFish JSTL on Tomcat
NoClassDefFoundError - LoopTag/ForEachTag
Installing JSTL 1.2 API JAR File
►JSTL Example - Loop Tag on Map Objects
Multiple Tags Working Together
Using Tomcat on CentOS Systems
Connecting to SQL Server from Servlet