JSP Tutorials - Herong's Tutorial Examples - v5.11, by Herong Yang
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) 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}<br/> </c:forEach> </body></html> </jsp:root>
Save JstlReqParam.jspx to \local\tomcat\webapps\ROOT, and run a Web browser 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 JAR? 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 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 tutorial on how to install JSTL 1.2 API JAR file.
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