I am working through an exercise to use the JSTL library in displaying an ArrayList, and up until this part I was having no issues. After the Maven project conversion and the addition of the JSTL dependency in the pom.xml, I am getting the common error:
The absolute uri: [http://java.sun.com/jsp/jstl/core] cannot be resolved in either web.xml or the jar files deployed with this application
I understand in some of the other occurrences of this question, Tomcat 10 requires the below as the dependency:
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
I am still not able to fix the error. Please see the necessary project files below.
ControllerServlet.java
package org.acr;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
/**
* Servlet implementation class ControllerServlet
*/
public class ControllerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ArrayList<String> bookTitles = new ArrayList<String>();
/**
* @see HttpServlet#HttpServlet()
*/
public ControllerServlet() {
super();
// TODO Auto-generated constructor stub
bookTitles.add("Lord of the Files");
bookTitles.add("A Tale of Two Servers");
bookTitles.add("To Catch a Throw");
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setAttribute("book_titles", bookTitles);
RequestDispatcher dispatcher = request.getRequestDispatcher("/BookList.jsp");
dispatcher.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter output = response.getWriter();
String title = request.getParameter("title");
String author = request.getParameter("author");
output.println("Book Title: " + title);
output.println("Book Author: " + author);
}
}
BookList.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:forEach items="${book_titles}" var="item">
<p>Book: ${item}</p>
</c:forEach>
</body>
</html>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>BookStore</groupId>
<artifactId>BookStore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd" id="WebApp_ID" version="5.0">
<display-name>BookStore</display-name>
<servlet>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>org.acr.ControllerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ControllerServlet</servlet-name>
<url-pattern>/books/*</url-pattern>
</servlet-mapping>
</web-app>
Clean Install:
<pre>[<font color="#12488B"><b>INFO</b></font>] <b>------------------------------------------------------------------------</b>
[<font color="#12488B"><b>INFO</b></font>] <font color="#C01C28"><b>BUILD FAILURE</b></font>
[<font color="#12488B"><b>INFO</b></font>] <b>------------------------------------------------------------------------</b>
[<font color="#12488B"><b>INFO</b></font>] Total time: 6.480 s
[<font color="#12488B"><b>INFO</b></font>] Finished at: 2022-10-06T17:11:13-04:00
[<font color="#12488B"><b>INFO</b></font>] <b>------------------------------------------------------------------------</b>
[<font color="#C01C28"><b>ERROR</b></font>] Failed to execute goal <font color="#2AA1B3">org.apache.maven.plugins:maven-war-plugin:2.2:wa</font><font color="#26A269">r</font> <b>(default-war)</b> on project <font color="#2AA1B3">BookStore</font>: <font color="#C01C28"><b>Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.2:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.2' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: Cannot access defaults field of Properties</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>-----------------------------------------------------</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>realm = plugin>org.apache.maven.plugins:maven-war-plugin:2.2</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[0] = file:/home/ats-admin/.m2/repository/org/apache/maven/plugins/maven-war-plugin/2.2/maven-war-plugin-2.2.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[1] = file:/home/ats-admin/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[2] = file:/home/ats-admin/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[3] = file:/home/ats-admin/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[4] = file:/home/ats-admin/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[5] = file:/home/ats-admin/.m2/repository/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[6] = file:/home/ats-admin/.m2/repository/org/codehaus/plexus/plexus-io/2.0.2/plexus-io-2.0.2.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[7] = file:/home/ats-admin/.m2/repository/org/codehaus/plexus/plexus-archiver/2.1/plexus-archiver-2.1.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[8] = file:/home/ats-admin/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.15/plexus-interpolation-1.15.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[9] = file:/home/ats-admin/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[10] = file:/home/ats-admin/.m2/repository/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[11] = file:/home/ats-admin/.m2/repository/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[12] = file:/home/ats-admin/.m2/repository/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>urls[13] = file:/home/ats-admin/.m2/repository/org/apache/maven/shared/maven-filtering/1.0-beta-2/maven-filtering-1.0-beta-2.jar</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>Number of foreign imports: 1</b></font>
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>import: Entry[import from realm ClassRealm[maven.api, parent: null]]</b></font>
[<font color="#C01C28"><b>ERROR</b></font>]
[<font color="#C01C28"><b>ERROR</b></font>] <font color="#C01C28"><b>-----------------------------------------------------</b></font>
[<font color="#C01C28"><b>ERROR</b></font>]
[<font color="#C01C28"><b>ERROR</b></font>] -> <b>[Help 1]</b>
[<font color="#C01C28"><b>ERROR</b></font>]
[<font color="#C01C28"><b>ERROR</b></font>] To see the full stack trace of the errors, re-run Maven with the <b>-e</b> switch.
[<font color="#C01C28"><b>ERROR</b></font>] Re-run Maven using the <b>-X</b> switch to enable full debug logging.
[<font color="#C01C28"><b>ERROR</b></font>]
[<font color="#C01C28"><b>ERROR</b></font>] For more information about the errors and possible solutions, please read the following articles:
[<font color="#C01C28"><b>ERROR</b></font>] <b>[Help 1]</b> http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
</pre>