java - 无法处理与 jstl 相关的 Jasper 验证错误
问题描述
我正在使用 jsp 和 jstl 作为视图模块创建一个 javaEE 项目。当我尝试构建它时,我得到不同的 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 验证器:绝对 uri: http: //java.sun.com/jsp/jstl/fmt无法在 web.xml 或随此应用程序部署的 jar 文件中解析
错误:Jasper 验证器:无法获取包含 TLD:java.net.MalformedURLException:路径 'http:/java.sun.com/jsp/jstl 的JAR 资源“ http://java.sun.com/jsp/jstl/fmt ” /fmt' 不以 '/' 开头;
错误:Jasper 验证器:无法找到 URI 的 taglib“fmt”:http: //java.sun.com/jsp/jstl/fmt;
错误:Jasper 验证器:org.apache.jasper.JasperException:java.lang.NullPointerException;
我之前遇到的错误:
错误:Jasper Validator:来自 /admin/addbook.jsp 中 c 的 TagLibraryValidator 的验证错误消息 null: org.xml.sax.SAXParseException; 行号:784;列号:8;在 CDATA 部分中发现了无效的 XML 字符 (Unicode: 0x0)。来自 /admin/addbook.jsp 中 fmt 的 TagLibraryValidator 的验证错误消息 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 文件夹中(我不知道是否需要它,但如果您的代码仍然损坏,您可以尝试)。
推荐阅读
- apache-nifi - 为什么一台机器上的NIFI Flow偶尔不能同步另一台机器?
- azure - 现有应用程序的配置模式失败,但适用于新创建的应用程序
- android - 验证受信任的 Web 活动以隐藏应用程序中的地址栏
- excel - 双击复制单元格并自动粘贴到另一张纸上的不同单元格
- c# - 如何在静态构造函数中使用 ILogger
- arrays - Unity - 在方法中添加多个数组参数(用于添加多个项目)
- r - 将多行转换为多列(长到宽格式不起作用(?))
- android - Android:当应用程序在前台时,Firebase 推送通知不同的图标,而当应用程序在后台时,另一个图标
- react-native - 如何在键盘打开时避免出现视图 | 反应原生
- oop - 如何使用内部类创建不同的对象