如何解决Eclipse使用JSTL需要什么JAR文件,以便最终在GAE / J上运行?
确保您的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>
或者,如果您的servlet容器支持它,则首选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>
否则,所有内容都会退回到最少支持的方式,并且标签库可能会像这样破坏。
另外,请确保您没有tld
在类路径(/WEB-
INF/lib
文件夹等)中散乱的文件,它们会与JAR文件中的文件冲突。哦,还要确保您没有在中手动定义tlds web.xml
,请保持干净。
解决方法
我已经花了比允许的更长的时间来尝试让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目录中)。
我的代码与输出如下:
<%@ 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
从该页面的最后一篇文章中,我认为我不需要standard.jar(http://forums.sun.com/thread.jspa?threadID=701267),无论如何我都无法在Oracle上找到它download.java.com网站以及jstl
jar。
编辑4:现在可以使用-步骤:
1)使用Apache版本
2)实际上将jar文件包含在构建路径中(右键单击eclipse项目并单击属性-> Java构建路径->库->添加类文件夹… ;默认情况下,war /
WEB-INF / lib显然不在构建路径上)
3)将文件c.tld添加到war / WEB-INF / tld
使您的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>
测试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>