有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Eclipse需要什么JAR文件才能使用JSTL,从而最终在GAE/J上工作?

为了让JSTL在Eclipse下(并最终在GAE/J下)工作,我已经尝试了很长时间。我已经下载了Eclipse,Eclipse的Google应用程序引擎扩展,以及JSTL(http://download.java.net/maven/1/jstl/jars/-JSTL-1.2.jar在WEB-INF\lib目录中)

下面是我的代码和输出:

<%@ 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 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

从本页最后一篇文章来看,我认为我不需要一个标准。jar(http://forums.sun.com/thread.jspa?threadID=701267),无论如何,我在Oracle下载中找不到一个。JAVAcom站点以及jstl jar

编辑4:立即工作-步骤:
1) 使用Apache版本
2) 实际上,在构建路径中包含jar文件(右键单击eclipse项目并点击属性->;Java构建路径->;库->;添加类文件夹…;默认情况下,war/WEB-INF/lib显然不在构建路径上)
3) 将文件c.tld添加到war/WEB-INF/tld

制作你的网页。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>

测试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>

共 (6) 个答案

  1. # 1 楼答案

    我也有同样的问题,我只是在taglib定义的末尾加上前缀=“c”

    之前:

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

    之后:

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

    所有警告都会从Eclipse中消失

  2. # 2 楼答案

    据我所知,你需要jstl。罐子和标准瓶。罐子把它们放在WEB-INF/lib下

  3. # 3 楼答案

    您只需在Maven POM中指定此依赖项:

    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    

    在我的代码中,这提供了以下JSP标记库工作所需的一切:

    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    
  4. # 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>
    

    或者,如果您的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是否支持最新版本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>
    

    否则,一切都将退回到最不受支持的MODU,taglib可能会像那样崩溃

    还要确保类路径中没有散乱的tld文件(包括/WEB-INF/lib文件夹),它们将与JAR文件中的文件发生冲突。哦,还要确保没有在web.xml中手动定义TLD,保持它干净

  5. # 5 楼答案

    将来自Apache的taglibs-standard-impl-1.2.5添加到项目的构建路径中。这可能会解决问题

  6. # 6 楼答案

    添加jstl-1.2-sources。将jar放入Tomcat\lib目录中