无法找到 URI 的 taglib [c]:[jakarta.tags.core] Tomcat 10.1.x

问题描述 投票:0回答:1

迁移到 spring 6.0.11 和 tomcat 10.1.13 后,我们开始遇到 jstl 和 jsp 的问题。 根据 Jakarta Standard Tag Library 3.0 文档,我已将所有 .jsp 文件中的 taglib uri 从 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 更改为 <%@ taglib prefix="c" uri="jakarta.tags.core" %>。经过调试,我发现TldCache类中的map没有被填充,这就是TagLibraryInfoImpl接收到的tldResourcePath为null的原因。 所有必需的库均已安装

implementation 'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0'
implementation 'org.glassfish.web:jakarta.servlet.jsp.jstl:3.0.1'
implementation 'org.mortbay.jasper:apache-jsp:10.1.7'
implementation("org.apache.tomcat:tomcat-jsp-api:10.1.13")
compileOnly "jakarta.servlet:jakarta.servlet-api:6.0.0"

可能是什么问题?

org.apache.jasper.JasperException: Could not find taglib [c] for URI: [jakarta.tags.core]
    in org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:54)
    in org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:294)
    in org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:81)
    in org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:176)
    in org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:429)
    in org.apache.jasper.compiler.Parser.parseDirective(Parser.java:487)
    in org.apache.jasper.compiler.Parser.parseElements(Parser.java:1444)
    in org.apache.jasper.compiler.Parser.parse(Parser.java:138)
    in org.apache.jasper.compiler.ParserController.doParse(ParserController.java:245)
    in org.apache.jasper.compiler.ParserController.parse(ParserController.java:106)
    in org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:211)
    in org.apache.jasper.compiler.Compiler.compile(Compiler.java:396)
    in org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)
    in org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    in org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
    in org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:396)
    in org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
    in org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
    in jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
    in org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205)
    in org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
    in org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    in org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
    in org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
    in org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:110)
    in org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
    in org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)

我还尝试添加额外的依赖项,例如

compileOnly 'jakarta.servlet.jsp:jakarta.servlet.jsp-api:3.1.1'
implementation 'org.mortbay.jasper:taglibs-standard:10.0.2'
compileOnly 'jakarta.platform:jakarta.jakartaee-api:10.0.0'

但这也没有帮助。使用 tomcat 9 和 java EE,添加起来很简单

implementation "jstl:jstl:1.2"  
implementation("org.apache.tomcat:tomcat-jsp-api:9.0.33")

我们得到了不同标签和所有作品的路径。

我还有自定义标签:

<taglib xmlns="https://jakarta.ee/xml/ns/jakartaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-jsptaglibrary_3_1.xsd"
        version="3.1">
    ...

对于自定义标签的任何问题,我不明白 apache-jsp 应该如何解析标签 jakarta.tags 的路径。*

gradle jstl tomcat10
1个回答
0
投票

我发现问题了。 我有 context.xml 和 JarScanFilter,用于扫描旧的 jar 命名。 更改为

tldScan="jakarta.servlet.jsp.jstl*.jar all works
old naming for tld jar scan

© www.soinside.com 2019 - 2024. All rights reserved.