Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSTL error javax/servlet/jsp/jstl/core/LoopTag error when using c:forEach tomcat ver7.0

Hi using
eclipse juno, dynamic web project
apache Tomcat v7.0 (which has its own jstl-1.2.1.jar) I get this error

javax.servlet.ServletException: java.lang.NoClassDefFoundError:  javax/servlet/jsp/jstl/core/LoopTag
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:343)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

when I try running this jsp code

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<c:forEach var="test" items="a,b,c">
${test}
</c:forEach>

</body>
</html>

it seams not to be seeing the javax.servlet.jsp.jstl.core.LoopTag class that is in the jar
I have read something about filters blocking javax.servlet files

any help would be greatly appreciated


ok I think I have found the solution javax.servlet.jsp.jstl-1.2.1.jar
does not contain the javax.servlet.jsp.jstl.core classes

jstl-1.2.jar needs to be added as well

like image 202
Andrew Beatty Avatar asked Oct 02 '12 16:10

Andrew Beatty


People also ask

What is c forEach in jsp?

Full Stack Java developer - Java + JSP + Restful WS + Spring The <c:forEach> tag is a commonly used tag because it iterates over a collection of objects. The <c:forTokens> tag is used to break a string into tokens and iterate through each of the tokens.

What is use of c forEach?

The <c:for each > is an iteration tag used for repeating the nested body content for fixed number of times or over the collection. These tag used as a good alternative for embedding a Java while, do-while, or for loop via a scriptlet.


3 Answers

javax.servlet.jsp.jstl-1.2.1.jar doesn't contain the javax.servlet.jsp.jstl.core classes. Be sure to add jstl-1.2.jar as well.

like image 105
lmat - Reinstate Monica Avatar answered Nov 08 '22 10:11

lmat - Reinstate Monica


If you are using maven, add

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jstl</artifactId>
  <version>1.1.2</version>
</dependency>

to your pom.xml

like image 35
maoyang Avatar answered Nov 08 '22 09:11

maoyang


If you want to use forEach you should add two libraries to WEB-INF/lib of your project: Impl: taglibs-standard-impl-1.2.5.jar Spec: taglibs-standard-spec-1.2.5.jar

like image 4
swch Avatar answered Nov 08 '22 10:11

swch