错误:即使添加了 CLASSPATH 变量,包 javax.servlet.http 也不存在

我正在尝试实现基本的 HelloServlet.java 程序。但它似乎产生了这些错误


HelloServlet.java:7: error: cannot find symbol

public class HelloServlet extends HttpServlet {

                                  ^

  symbol: class HttpServlet

HelloServlet.java:11: error: cannot find symbol

   public void init() throws ServletException {

                             ^

  symbol:   class ServletException

  location: class HelloServlet

HelloServlet.java:16: error: cannot find symbol

   public void doGet(HttpServletRequest request, HttpServletResponse response)

                     ^

  symbol:   class HttpServletRequest

  location: class HelloServlet

HelloServlet.java:16: error: cannot find symbol

   public void doGet(HttpServletRequest request, HttpServletResponse response)

                                                 ^

  symbol:   class HttpServletResponse

  location: class HelloServlet

HelloServlet.java:17: error: cannot find symbol

      throws ServletException, IOException {

             ^

  symbol:   class ServletException

  location: class HelloServlet

HelloServlet.java:3: error: package javax.servlet does not exist

import javax.servlet.*;

^

HelloServlet.java:4: error: package javax.servlet.http does not exist

import javax.servlet.http.*;

^

7 errors

我已经为 jar 文件添加了 CLASSPATH


nithinchandranp@b-40:~$ echo ${CLASSPATH}

/home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/*

nithinchandranp@b-40:~$ 

现在我做错了什么?请帮忙..


繁星coding
浏览 279回答 3
3回答

慕容森

末尾带有 * 的类路径不适用于 jar 数据集。您必须将每个 jar 放在类路径中。

小唯快跑啊

这是我的错误。这就是我通过命令行创建 CLASSPATH 的方式 export CLASSPATH=/home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/*我创建的目录不是ApacheTomcat,而是Apache Tomcat(中间有一个空格)。也许这就是 CLASSPATH 变量无法识别正确位置的原因。我将目录名称更改为 ApacheTomcat(删除了空格)。现在我在 .bashrc 文件中定义了 CLASSPATH 变量,如下所示:#classpathexport CLASSPATH=/home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/*现在,当我执行 echo${CLASSPATH} 时,我得到了我提到的所有 jar 文件。nithinchandranp@b-40:~$ echo ${CLASSPATH}/home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/annotations-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/catalina-ant.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/catalina-ha.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/catalina.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/catalina-storeconfig.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/catalina-tribes.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/ecj-4.6.3.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/el-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/jasper-el.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/jasper.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/jaspic-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/jsp-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/servlet-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-coyote.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-dbcp.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-i18n-es.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-i18n-fr.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-i18n-ja.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-i18n-ru.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-jdbc.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-jni.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-util.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-util-scan.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-websocket.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/websocket-api.jar
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java