我正在创建一个 javaEE 项目,其中包含 jsp 和 jSTL 作为 View 模块。当我尝试构建它时,我收到不同的 Jasper 验证错误。使用maven和tomcat 9.0.21作为服务器,所有编码设置为utf-8
我已将 jSTL-1.2.jar 添加到项目设置 -> 库和 war:exploded -> WEB-INF/lib。我还尝试删除依赖项并设置不同的版本。 如果我删除 <%@ taglib %> fmt 和 c 声明,页面将正常工作(至少不会导致服务器 500 错误)。
JSP:
{<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="${param.lang}">
<fmt:setLocale value="${param.lang}"/>
<fmt:bundle basename="message"/>
<head>
<title>Book list</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"/>
<link rel="stylesheet" href="WEB-INF/css/base.css"/>
</head>
<body>
<header>
<div class="row" id="lang">
<div class="col-2 justify-content-start" id="appName">Library app</div>
<div class="col-6"></div>
<div class="col-2 justify-content-end">
<p id="langLabel">Choose language:</p>
</div>
<div class="col-1 justify-content-center">
<a href="?lang=ua"><img src="../WEB-INF/images/uaFlag.jpg" alt="ua"/></a>
<a href="?lang=en"><img src="../WEB-INF/images/gbFlag.svg" alt="en"/></a>
</div>
<div class="col-1">
<form action="${pageContext.request.contextPath}/logout" id="logoutForm">
<button type="submit" id="logoutButton">Logout</button>
</form>
</div>
</div>
</header>
<div class="row" id="contentDiv">
<div class="content contentFirstBlock col-7 justify-content-center">
<div id="addbookFormBlock">
<form id="addbookForm">
<fmt:message key="input.addbook.bookName" var="bookName"/>
<fmt:message key="input.addbook.bookGenre" var="bookGenre"/>
<fmt:message key="input.addbook.bookIsbn" var="bookIsbn"/>
<fmt:message key="input.addbook.bookYearPublished" var="bookYearPublished"/>
<fmt:message key="input.addbook.submitAddBook" var="submitAddBook"/>
<label for="bookName">${bookName}</label><input type="text" id="bookName" name="bookName" autocomplete="off" required="required"/><br/>
<label for="bookGenre">${bookGenre}</label><input type="text" id="bookGenre" name="bookGenre" autocomplete="off" required="required"/><br/>
<label for="bookIsbn">${bookIsbn}</label><input type="text" id="bookIsbn" name="bookIsbn" autocomplete="off" required="required"/><br/>
<label for="bookYearPublished">${bookYearPublished}</label><input type="text" id="bookYearPublished" name="bookYearPublished" autocomplete="off" required="required"/><br/>
<input type="submit" id="submitAddButton" name="submitBook" value="${submitAddBook}"/>
</form>
</div>
</div>
<div class="content contentSecondBlock col-5">
<p>Sample</p>
<table>
<tr>
<td>Select</td>
<td>Author id</td>
<td>Author first name</td>
<td>Author last name</td>
</tr>
<c:forEach items="${authors}" var="author">
<tr>
<td><input type="checkbox" name="aths" value="${author.getAuthorId()}"/></td>
<td>${author.getAuthorId()}</td>
<td>${author.getAuthorFirstName()}</td>
<td>${author.getAuthorLastName()}</td>
</tr>
</c:forEach>
</table>
</div>
</div>
<footer>footer</footer>
</body>
</html>}
依赖关系
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/taglibs/standard -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.el/el-api -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- mySql connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
最近的一组错误:
错误:Jasper validator :绝对 uri:http://java.sun.com/jsp/jstl/fmt无法在 web.xml 或使用此应用程序部署的 jar 文件中解析
错误:Jasper validator :无法获取包含 TLD 的 JAR 资源“http://java.sun.com/jsp/jstl/fmt”:java.net.MalformedURLException:路径“http://java.sun.com/jsp/jSTL/fmt”不以“/”开头';
错误:Jasper validator :无法找到 URI 的 taglib“fmt”:http://java.sun.com/jsp/jstl/fmt ;
错误:Jasper validator :org.apache.jasper.JasperException:java.lang.NullPointerException;
我之前遇到的错误:
错误:Jasper Validator:来自 TagLibraryValidator 的/admin/addbook.jsp 中 c 的验证错误消息 null:org.xml.sax.SAXParseException;行号:784;列数:8;在 CDATA 部分中发现无效的 XML 字符(Unicode:0x0)。来自 TagLibraryValidator 的/admin/addbook.jsp 中 fmt 的验证错误消息 null:org.xml.sax.SAXParseException;行号:784;列数:8;在 CDATA 部分中发现无效的 XML 字符(Unicode:0x0)。
最佳答案
好的,我已经解决了这个问题,也许会对某人有所帮助。
依赖关系:
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
</dependencies>
我刚刚将代码从 jsp 复制到另一个空 jsp 文件并删除了第一个。之后(以及依赖项的修改)验证成功通过。另外,我删除了 WEB-INF/lib 中的所有 jar 并将 jSTL-1.2.jar 添加到 tomcat/lib 文件夹中(我不知道是否需要它,但如果您的代码仍然损坏,您可以尝试)。
关于java - 无法处理与 jSTL 相关的 Jasper 验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56650357/