Class 未找到 TLD 函数的方法签名中指定的 - JasperException

Class Specified in Method signature of TLD function is not found - JasperException

我正在将一个项目从遗留 spring 迁移到 springboot。项目使用 Spring Webflow 并计划保持 webflow 的配置不变,并通过更新项目结构和添加必要的启动库将项目移植到 springboot。

目前遇到来自嵌入式 tomcat jasper 库的 jasperexception,抱怨未找到 TLD 的方法签名中用于函数的 class。

org.apache.jasper.JasperException: The class [javax.servlet.http.HttpServletRequest request] specified in the method signature in TLD for the function [mytld:getAppLink] cannot be found. [javax.servlet.http.HttpServletRequest request] at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:55) ~[tomcat-embed-jasper-9.0.36.jar!/:9.0.36] at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:294) ~[tomcat-embed-jasper-9.0.36.jar!/:9.0.36] at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:81) ~[tomcat-embed-jasper-9.0.36.jar!/:9.0.36]

如果我将 TLD 中的函数更新为无参数函数,那么此时它可以正常工作。但是当我有一个 class 传递给构造函数时,这个错误被抛出。

JSP:

<%@ include file="/WEB-INF/jsp/includes/includes.jspf" %>
<%@ taglib prefix="mytld" uri="MyTldLibrary" %>
<div id="header" class="style-header">
    <div id="headm">
        <a href="${mytld:getAppLink(pageContext.request)}" class="logos"></a>
        
    </div>
</div>

这是我的顶级域名的片段:

<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_2.xsd"
    version="2.0">

    <tlib-version>2.2</tlib-version>
    <jsp-version>3.0</jsp-version>
    <short-name>mytld</short-name>
    <uri>MyTldLibrary</uri>
    <description>App EL Functions</description>
    
    <function>
        <name>getAppLink</name>
        <function-class>
            com.app.web.tags.AppWebFunctions
        </function-class>
        <function-signature>
            java.lang.String getAppLink(javax.servlet.http.HttpServletRequest request)
        </function-signature>
    </function>
</taglib>

这是 AppWebFunctions class:

中函数 getAppLink 的片段
/**
     * Gets the App link.
     *
     * @param request the request
     * @return the App link
     * @throws UnsupportedEncodingException the unsupported encoding exception
     */
    public static final String getAppLink(final HttpServletRequest request) throws UnsupportedEncodingException {
        //LOGIC to retrieve applink
        return appLink;
    }

If I update the function in TLD to a no argument function, it works fine at that point. But moment I have a class to pass in the constructor this error is thrown.

这是因为<function-signature>不包含任何参数名称,只能指定参数类型的完全限定class名称

因此,只需删除 request 参数名称,TLD 就可以正常工作了。

<function-signature>
    java.lang.String getAppLink(javax.servlet.http.HttpServletRequest)
</function-signature>