$ java -version java version "1.6.0_45" Java(TM) SE Runtime
Environment (build 1.6.0_45-b06-451-10M4406) Java HotSpot(TM) 64-Bit
Server VM (build 20.45-b01-451, mixed mode)
Tomcat版本:7.0.40
我在这里关注开始的servlet / jsp教程:
https://stackoverflow.com/tags/servlets/info
我收到此错误:
HTTP状态500 - 绝对uri: http://java.sun.com/jsp/jstl/functions无法解决 web.xml或使用此应用程序部署的jar文件
看起来它来自以这行开头的.jsp文件:
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html lang="en">
我像这样编译了我的servlet:
~/java_programs/modernServlet$ javac -cp /Library/Tomcat/lib/servlet-api.jar -d classes src/com/example/controller/HelloServlet.java
然后我将该文件复制到Tomcat目录中WEB-INF类下的相同目录结构中。我应该在classpath中包含一些其他jar文件吗?
====
好的,我下载并将jstl jar复制到Tomcat的lib目录,现在我得到了各种编译错误:
$ javac -cp "/Library/Tomcat/lib/servlet-api.jar;/Library/Tomcat/lib/jstl-1.2.jar" -d classes src/com/example/controller/HelloServlet.java
src/com/example/controller/HelloServlet.java:7: package javax.servlet does not exist
import javax.servlet.ServletException;
^
src/com/example/controller/HelloServlet.java:8: package javax.servlet.annotation does not exist
import javax.servlet.annotation.WebServlet;
^
src/com/example/controller/HelloServlet.java:9: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;
^
src/com/example/controller/HelloServlet.java:10: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletRequest;
^
src/com/example/controller/HelloServlet.java:11: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
^
src/com/example/controller/HelloServlet.java:14: cannot find symbol
symbol: class HttpServlet
public class HelloServlet extends HttpServlet {
^
src/com/example/controller/HelloServlet.java:13: cannot find symbol
symbol: class WebServlet
@WebServlet("/hello")
^
src/com/example/controller/HelloServlet.java:17: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.controller.HelloServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
^
src/com/example/controller/HelloServlet.java:17: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.controller.HelloServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
^
src/com/example/controller/HelloServlet.java:17: cannot find symbol
symbol : class ServletException
location: class com.example.controller.HelloServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
^
src/com/example/controller/HelloServlet.java:23: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.controller.HelloServlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
^
src/com/example/controller/HelloServlet.java:23: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.controller.HelloServlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
^
src/com/example/controller/HelloServlet.java:23: cannot find symbol
symbol : class ServletException
location: class com.example.controller.HelloServlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
^
src/com/example/controller/HelloServlet.java:16: method does not override or implement a method from a supertype
@Override
^
src/com/example/controller/HelloServlet.java:22: method does not override or implement a method from a supertype
@Override
^
15 errors
答案 0 :(得分:1)
这不是编译错误。这是运行时错误。
您只需按照JSTL tag wiki page(以及间接JSP tag wiki page)的说明将JSTL放入/WEB-INF/lib
。
您无需在编译时类路径中指定它。它是运行时错误,而不是编译错误。你成功编译了servlet,对吗?
尝试使用类路径中的JSTL进行编译时出现编译错误是因为您在使用基于Unix的操作系统时在类路径中使用特定于Windows的路径分隔符;
,这需要{{1} }作为路径分隔符。但毕竟,在编译时类路径中不需要JSTL。
答案 1 :(得分:0)
您需要将JSTL jar添加到Tomcat lib文件夹中。
您可以在此处下载:http://mvnrepository.com/artifact/javax.servlet/jstl/1.2
单击“下载”按钮,然后将该文件复制到Tomcat的lib文件夹中。
新错误意味着类路径中缺少servlet-api.jar。