Search code examples
javaxmlmaven

JasperException: Absolute uri cannot be resolved


I have been getting the following JasperException when trying to use an XML schema for my web.xml, instead of the deprecated DOCTYPE declaration:

HTTP Status 500 - 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

If I use this web.xml, the application compiles:

<!DOCTYPE web-app PUBLIC 
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>
</web-app>

However, if I use this web.xml, I get the JasperException:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
    <display-name>CourseManagementJDBC</display-name>\
</web-app>

Any idea why only a deprecated format would work?

NOTE: This is for a Maven project, and the JSTL dependency has been correctly declared, as well as the tag library in the JSP:

pom.xml:

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

JSP:

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

They're all correct; what gives?


Solution

  • I finally came upon the solution. By default, for some reason (and I'd like to know why), Maven generates a Dynamic Web Module as version 2.3. DTD was of course the standard for Servlet 2.3 and was probably unable to parse or evaluate my XML-based web.xml file.

    I'm still not 100% clear as to why changing web.xml to XSD caused the JasperException with respect to JSTL, though I think it has something to do with JSTL being integrated with JSP at some point after Servlet 2.3 - someone please correct or elaborate on this if possible.

    See this: https://stackoverflow.com/a/4928309/2879303

    Now for the solution:

    1. Right-click on your Maven project and select Properties

    2. Navigate to Project Facets and untick Dynamic Web Module. Apply changes.

    3. From the version drop-down box, select the latest version (as of writing, this is 3.1). Re-select Dynamic Web Module. Apply changes.

    4. Right-click on your Maven project and select Maven -> Update Project.

    5. Your project should now be able to correctly interpret a web.xml with an XSD declaration.