Error in <c:forEach> tag in JSTL while using Eclipse

Viewed 653

I am learning JSTL and I have downloaded JSTL 2.0.0 from here because jstl 1.2.2 was using javax and I am using jakarta.

display.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <c:out value="Jai Swaminarayan"/>

    <c:forEach items="${students}" var="s">
        ${s} <br/><br/>
    </c:forEach>
    
    </body>
</html>

This code keeps throwing the following error:

Error on Eclipse

A problem was encountered using TagExtraInfo class 
 org.apache.taglibs.standard.tei.ForEachTEI for 'c:forEach'

Error on Webpage

HTTP Status 500 – Internal Server Error
Type Exception Report
Message java.lang.NoClassDefFoundError: jakarta/servlet/jsp/jstl/core/LoopTag
Description The server encountered an unexpected condition that prevented it from fulfilling the request.

I have even added .jar file to Build Path and WEB-INF Folder. I do Not think this issue is with .jar file but I could be wrong.

Here, <c:out> is working perfectly but it only throws error in <c:forEach> tag. I checked the files in jakarta.servlet.jsp.jstl-2.0.0.jar and file named forEachTag.class Does Exists in org.apache.taglibs.standard.tei.ForEachTEI


Software Data:

Java Version: 15.0.2 | Server: Tomcat-10 | IDE: Eclipse


What I tried:

I cannot find the source but some answer asked to remove whitespace between <%@ and taglib

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

Trying since long time. Any help is appreciable :)

1 Answers

I had the same problem as you, I did like the comment said and looked at dependencies, downloaded and put the one below in the webapp/Web-inf/lib folder and it worked after that.

Related