Java Eclipse 需要哪些 JAR 文件才能使用 JSTL 才能最终在 GAE/J 上运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4052552/
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
What JAR files are needed for Eclipse to use JSTL so it ultimately works on GAE/J?
提问by user45492
I've been trying for longer than I'd like to admit to get JSTL working under Eclipse (and ultimately under GAE/J). I've downloaded Eclipse, the Google App Engine Extension for Eclipse, and JSTL (http://download.java.net/maven/1/jstl/jars/- jstl-1.2.jar is in the WEB-INF\lib directory).
我一直在尝试让 JSTL 在 Eclipse 下工作(并最终在 GAE/J 下工作),这比我承认的要长。我已经下载了 Eclipse、Eclipse 的 Google App Engine 扩展和 JSTL(http://download.java.net/maven/1/jstl/jars/- jstl-1.2.jar 在 WEB-INF\lib 目录中)。
My code is below along with the output:
我的代码与输出一起在下面:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<HTML><HEAD><TITLE>Test Page</TITLE></HEAD><BODY>
Test Page
<c:set var="myvar" value="3"/>
</BODY></HTML>
The error I get is:
我得到的错误是:
The tag handler class for "c:set" (org.apache.taglibs.standard.tag.rt.core.SetTag) was not found on the Java Build Path
test.jsp
[my app's path and name]
line 8
JSP Problem
From the last post on this page I don't think I need a standard.jar (http://forums.sun.com/thread.jspa?threadID=701267) and in any case I couldn't find one on the Oracle download.java.com site along with the jstl jar.
从本页上的最后一篇文章中,我认为我不需要一个 standard.jar(http://forums.sun.com/thread.jspa?threadID=701267),无论如何我在 Oracle 上找不到download.java.com 站点以及 jstl jar。
EDIT 4: Works now - Steps:
1) Use the Apache version
2) Actually include the jar file in the build path (right click the eclipse project and hit Properties -> Java Build Path -> Libraries -> Add Class Folder...; the war/WEB-INF/lib is apparently not on the build path by default)
3) Add the file c.tld to war/WEB-INF/tld
编辑 4:现在工作 - 步骤:
1)使用 Apache 版本
2)实际上将 jar 文件包含在构建路径中(右键单击 eclipse 项目并点击 Properties -> Java Build Path -> Libraries -> Add Class Folder... ; 默认情况下,war/WEB-INF/lib 显然不在构建路径上)
3) 将文件 c.tld 添加到 war/WEB-INF/tld
Make your web.xml look like:
让你的 web.xml 看起来像:
<\?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>JSTLExample</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
The test jsp file contents:
测试jsp文件内容:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- Taglib -->
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test Apache ServiceMix with JSTL</title>
</head>
<body>
This is a testpage.
<%= "hello" %>
<c:forEach var="i" begin="1" end="10" step="1">
<c:out value="${i}" />
<br />
</c:forEach>
</body>
</html>
采纳答案by BalusC
Ensure that your web.xmlroot declaration complies at leastServlet 2.4.
确保您的web.xml根声明至少符合Servlet 2.4。
<web-app
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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<!-- Config here. -->
</web-app>
Or if your servletcontainer supports it, prefer 2.5:
或者,如果您的 servletcontainer 支持它,则更喜欢 2.5:
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<!-- Config here. -->
</web-app>
O if it supports the latest version3.0
O 如果支持最新版本3.0
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- Config here. -->
</web-app>
Otherwise everything will fall back to least supported modus and taglibs may break like that.
否则一切都会退回到最不支持的模式,标签库可能会像那样崩溃。
Also ensure that you don't have loose tldfiles wandering around in the classpath (the /WEB-INF/libfolder, among others), they will collide with the ones in JAR files. Oh, also ensure that you didn't manually define the tlds in web.xml, keep it clean.
还要确保您没有tld在类路径(/WEB-INF/lib文件夹等)中四处游荡的松散文件,它们会与 JAR 文件中的文件发生冲突。哦,还要确保您没有手动定义 中的 tld web.xml,保持干净。
回答by kukudas
As far as i know you need jstl.jar and standard.jar. Put those under WEB-INF/lib.
据我所知,您需要 jstl.jar 和 standard.jar。将它们放在 WEB-INF/lib 下。
回答by Jubz
You only need to specify this dependency in your Maven POM:
您只需要在 Maven POM 中指定此依赖项:
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
In my code, this provided everything I needed for the following JSP taglib to work:
在我的代码中,这提供了以下 JSP taglib 工作所需的一切:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
回答by user1716015
I had the same issue and I simply put the prefix = "c" at the endof the taglib definition
我遇到了同样的问题,我只是在 taglib 定义的末尾加上前缀 = "c"
before:
前:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
after:
后:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
And all warnings disappear from Eclipse.
并且所有警告都从 Eclipse 中消失了。
回答by Praveer Satyam
Add taglibs-standard-impl-1.2.5from Apacheto the build path of the project. This may resolve the issue.
添加标签库,标准IMPL-1.2.5从阿帕奇到项目的构建路径。这可能会解决问题。
回答by ZEESHAN KHAN
add jstl-1.2-sources.jar into your Tomcat\lib directory
将 jstl-1.2-sources.jar 添加到您的 Tomcat\lib 目录中

