Java JSP 片段中的未知标签和未定义函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24325178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:34:16  来源:igfitidea点击:

Unknown tags and undefined functions in JSP fragments

javajspjsp-tagsjsp-fragments

提问by Mohamed Khamis

I imported a web project build in JSP, which I am relatively new to. I got some errors in WEB-INF/includes/componentsthat I am unable to resolve.

我在 JSP 中导入了一个 Web 项目构建,我对它比较陌生。我遇到了一些WEB-INF/includes/components无法解决的错误。

Some .jspffiles show me errors such as at that line:

一些.jspf文件向我显示了错误,例如在该行:

<c:if test="${fn:length(view.parent.views) > 1}">

the error is:

错误是:

Multiple annotations found at this line:
- The function fn:length is 
 undefined
- Unknown tag (c:if).

I also get errors like The function fn:length is undefinederrors for fn:length.

我也得到这样的错误The function fn:length is undefined的错误fn:length

I followed up with other questions and made sure that standard.jarand jstl-1.2.jarare included in my build path. Moreover, WEB-INF/includes/taglibs.jspfhas the following :

我跟进其他问题,并作了肯定standard.jar,并jstl-1.2.jar包括在我的构建路径。此外,WEB-INF/includes/taglibs.jspf还有以下几点:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

采纳答案by Mohamed Khamis

It works if I add the following at the beginning of my JSP file:

如果我在 JSP 文件的开头添加以下内容,它会起作用:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ taglib prefix="nav" uri="/WEB-INF/taglibs/navigation.tld" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

This is a working answer for now, but I think the best answer would be the one that tells how it can be sufficient to include the lines above in taglibs.jspf, instead of having them in every .jspfile.

这是目前一个可行的答案,但我认为最好的答案是说明如何将上面的行包含在 中taglibs.jspf,而不是将它们包含在每个.jsp文件中。

回答by Gabriel

I recently faced same problem. I added a base.jspf file and referred it on the top of the file:

我最近遇到了同样的问题。我添加了一个 base.jspf 文件并在文件顶部引用它:

<%@ include file="/WEB-INF/includes/base.jspf" %>

That file contains

该文件包含

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>