NoClassDefFoundError - LoopTag/ForEachTag

This section provides a tutorial example on how to use JSTL loop tags with EL expressions. JSTL 1.2 API JAR file is needed.

One important feature of JSTL is that JSTL tags can use EL expressions to generate dynamic data in a very simple way. For example, the following JSP page, JstlReqParam.jspx, shows you how to the <c:forEach%gt; tag to list all parameters in the HTTP request with the help of EL expressions:

<?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"> 
<!-- JstlReqParam.jspx
 - Copyright (c) 2012, 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}<br/>
</c:forEach>
</body></html>
</jsp:root>

Save JstlReqParam.jspx to \local\apache-tomcat-7.0.32\webapps\ROOT, and run IE with URL: http://localhost:8080/JstlReqParam.jspx?name=herong&lang=JSP.

Surprisingly, I am getting the Java exception:

HTTP Status 500 - javax.servlet.ServletException: 
   java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/LoopTag

type Exception report

message javax.servlet.ServletException: 
   java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/LoopTag

description The server encountered an internal error 
   that prevented it from fulfilling this request.

exception 
org.apache.jasper.JasperException: javax.servlet.ServletException: 
   java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/LoopTag
   org.apache.jasper.servlet.JspServletWrapper.handleJspException()
   org.apache.jasper.servlet.JspServletWrapper.service()
   org.apache.jasper.servlet.JspServlet.serviceJspFile()
   org.apache.jasper.servlet.JspServlet.service()
   javax.servlet.http.HttpServlet.service()

root cause 
javax.servlet.ServletException: java.lang.NoClassDefFoundError: 
   javax/servlet/jsp/jstl/core/LoopTag
   org.apache.jasper.runtime.PageContextImpl.doHandlePageException()
   org.apache.jasper.runtime.PageContextImpl.handlePageException()
   org.apache.jsp.JstlReqParam_jspx._jspService()
   org.apache.jasper.runtime.HttpJspBase.service()
   javax.servlet.http.HttpServlet.service()
   org.apache.jasper.servlet.JspServletWrapper.service()
   org.apache.jasper.servlet.JspServlet.serviceJspFile()
   org.apache.jasper.servlet.JspServlet.service()
   javax.servlet.http.HttpServlet.service()

... 

If I reload this JSP page, I am getting different Java exception:

HTTP Status 500 - javax.servlet.ServletException: 
   java.lang.NoClassDefFoundError: 
   org/apache/taglibs/standard/tag/rt/core/ForEachTag

type Exception report

message javax.servlet.ServletException: 
   java.lang.NoClassDefFoundError: 
   org/apache/taglibs/standard/tag/rt/core/ForEachTag

description The server encountered an internal error 
   that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: javax.servlet.ServletException: 
   java.lang.NoClassDefFoundError: 
   org/apache/taglibs/standard/tag/rt/core/ForEachTag
   org.apache.jasper.servlet.JspServletWrapper.handleJspException()
   org.apache.jasper.servlet.JspServletWrapper.service()
   org.apache.jasper.servlet.JspServlet.serviceJspFile()
   org.apache.jasper.servlet.JspServlet.service()
   javax.servlet.http.HttpServlet.service()

...

Why? Did I miss anything when Installing GlassFish JSTL 1.2? Why the <c:out> tag is working, the <c:forEach%gt; is not?

After some research on the Internet, I realize that the JSTL 1.2 API JAR is missing on my Tomcat 7 server. What I installed from GlassFish JSTL 1.2 is the implementation JAR file. The API JAR is needed to support "loop" tags like <c:forEach%gt;

See the next section on how to install JSTL 1.2 API JAR file.

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

 References

 PDF Printing Version