java 错误:包 javax.servlet.http 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11472455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: package javax.servlet.http does not exist
提问by M_x_r
I am trying to create my first servlet and I am getting the error above when I try to compile my code. I have read on stackoverflow that this is due to SE JDK not containing the servlet api. However, I am compiling from the command line with the following:
我正在尝试创建我的第一个 servlet,当我尝试编译我的代码时出现上述错误。我在 stackoverflow 上读到这是由于 SE JDK 不包含 servlet api。但是,我正在从命令行使用以下内容进行编译:
javac -classpath C:/Tomcat7/lib/servlet-api.jar;
-d ../classes com/example/web/BeerSelect.java.
As you can see I am making reference to the servlet-api on the command line. Please can you advise why I am still getting this error. I am using tomcat 7
如您所见,我在命令行上引用了 servlet-api。请你告诉我为什么我仍然收到这个错误。我正在使用 tomcat 7
thanks
谢谢
Solution
解决方案
For anyone that is interested..I located my problem. It was problem with the Windows command shell and the fact that I had spaces in the directory names. I had the tomcat app saved as "tomcat 7" with a space. I was trying to reach it with "tomcat7" - that is no spaces.. The following line works
对于任何感兴趣的人..我找到了我的问题。Windows 命令外壳有问题,而且我的目录名称中有空格。我将 tomcat 应用程序保存为带有空格的“tomcat 7”。我试图用“tomcat7”到达它 - 那是没有空格..以下行有效
javac -classpath .;C:/Tomcat7/lib/servlet-api.jar;
-d ../classes com/example/web/BeerSelect.java
回答by Jér?me Verstrynge
回答by Will
Change the forward slashes to back slashes, remove the trailing semicolon after the JAR, and try again:
把正斜杠改成反斜杠,去掉JAR后面的分号,再试一次:
javac -classpath C:\Tomcat7\lib\servlet-api.jar -d ..\classes com\example\web\BeerSelect.java
Also double-check all the paths, especially servlet-api.jar.
还要仔细检查所有路径,尤其是 servlet-api.jar。