无法处理与jstl

时间:2019-06-18 13:30:56

标签: java jsp servlets jstl

我正在创建一个使用jsp和jstl作为视图模块的javaEE项目。当我尝试建立连接时,会遇到不同的“碧玉验证”错误。使用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的JAR资源“ http://java.sun.com/jsp/jstl/fmt”:java.net.MalformedURLException:路径'http:/java.sun.com/jsp/jstl/fmt'开头不是'/';

错误:Jasper验证程序:无法找到URI的taglib“ fmt”:http://java.sun.com/jsp/jstl/fmt;

错误:Jasper验证程序:org.apache.jasper.JasperException:java.lang.NullPointerException;

我之前遇到的错误:

错误:Jasper验证程序:来自TagLibraryValidator的/admin/addbook.jsp中c的验证错误消息null:org.xml.sax.SAXParseException; lineNumber:784; columnNumber:8;在CDATA部分中发现了无效的XML字符(Unicode:0x0)。来自TagLibraryValidator的/admin/addbook.jsp中fmt的验证错误消息为null:org.xml.sax.SAXParseException; lineNumber:784; columnNumber:8;在CDATA部分中发现了无效的XML字符(Unicode:0x0)。

1 个答案:

答案 0 :(得分:0)

好的,我已经解决了这个问题,也许它将对某人有所帮助。

依赖项:

    <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文件夹中(我不知道是否需要它,但是如果您的代码仍然损坏,则可以尝试)。