use*_*492 14 java eclipse google-app-engine jsp servlets
我一直在尝试的时间超过了我想承认让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>
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
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
Run Code Online (Sandbox Code Playgroud)
从本页的最后一篇文章中我不认为我需要一个standard.jar(http://forums.sun.com/thread.jspa?threadID=701267),无论如何我在Oracle上找不到一个download.java.com网站以及jstl jar.
编辑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
使您的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>
Run Code Online (Sandbox Code Playgroud)
测试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>
Run Code Online (Sandbox Code Playgroud)
小智 26
我遇到了同样的问题,我只是将前缀="c" 放在 taglib定义的末尾
之前:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Run Code Online (Sandbox Code Playgroud)
后:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
Run Code Online (Sandbox Code Playgroud)
所有警告都从Eclipse中消失.
您只需要在Maven POM中指定此依赖项:
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在我的代码中,这提供了以下JSP taglib工作所需的一切:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
Run Code Online (Sandbox Code Playgroud)
确保您的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>
Run Code Online (Sandbox Code Playgroud)
或者,如果您的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>
Run Code Online (Sandbox Code Playgroud)
如果它支持最新版本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>
Run Code Online (Sandbox Code Playgroud)
否则一切都将回落到支持最少的modus,而taglib可能会破坏.
还要确保您没有tld在类路径(/WEB-INF/lib文件夹等)中闲逛的松散文件,它们将与JAR文件中的文件冲突.哦,还要确保你没有手动定义tlds web.xml,保持干净.
| 归档时间: |
|
| 查看次数: |
50353 次 |
| 最近记录: |