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
Unknown tags and undefined functions in JSP 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/components
that I am unable to resolve.
我在 JSP 中导入了一个 Web 项目构建,我对它比较陌生。我遇到了一些WEB-INF/includes/components
无法解决的错误。
Some .jspf
files 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 undefined
errors for fn:length
.
我也得到这样的错误The function fn:length is undefined
的错误fn:length
。
I followed up with other questions and made sure that standard.jar
and jstl-1.2.jar
are included in my build path. Moreover, WEB-INF/includes/taglibs.jspf
has 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 .jsp
file.
这是目前一个可行的答案,但我认为最好的答案是说明如何将上面的行包含在 中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" %>