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:


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.1"> 
<!-- JstlReqParamRevised.jspx
 - Copyright (c) 2012, HerongYang.com, All Rights Reserved.
<jsp:directive.page contentType="text/html"/>
<p>List of Request Parameters:</p>
<c:forEach items="${pageContext.request.parameterMap}" var="entry">
   ${entry.key} = 
   <c:forEach items="${entry.value}" var="value">

Save JstlReqParamRevised.jspx to \local\apache-tomcat-7.0.32\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.

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)

 What is JSTL?

 Installing GlassFish JSTL 1.2 on Tomcat 7

 "Hello world!" with JSTL

 JSTL in XML Style JSP Pages

 General Syntax of JSTL Tags

 NoClassDefFoundError - LoopTag/ForEachTag

 Installing JSTL 1.2 API JAR File

JSTL Example - Loop Tag on Map Objects

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Outdated Tutorials


 PDF Printing Version