What JAR files are needed for Eclipse to use JSTL

2019-03-12 21:12发布

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).

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.

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

Make your web.xml look like:

<\?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:

 <?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>

5条回答
兄弟一词,经得起流年.
2楼-- · 2019-03-12 21:17

Add taglibs-standard-impl-1.2.5 from Apache to the build path of the project. This may resolve the issue.

查看更多
虎瘦雄心在
3楼-- · 2019-03-12 21:38

You only need to specify this dependency in your 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:

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
查看更多
聊天终结者
4楼-- · 2019-03-12 21:40

I had the same issue and I simply put the prefix = "c" at the end of the taglib definition

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.

查看更多
虎瘦雄心在
5楼-- · 2019-03-12 21:44

Ensure that your web.xml root declaration complies at least 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:

<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

<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 tld files wandering around in the classpath (the /WEB-INF/lib folder, 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.

查看更多
劳资没心,怎么记你
6楼-- · 2019-03-12 21:44

As far as i know you need jstl.jar and standard.jar. Put those under WEB-INF/lib.

查看更多
登录 后发表回答