eclipse 我的 JDK 中没有 javax.servlet 包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14603062/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:54:00  来源:igfitidea点击:

There is no javax.servlet package in my JDK

javaeclipseenvironment-variables

提问by Little Child

I am following Head First: Servlet and JSPand I was writing my first Servlet.
I tried to compile it using command line and I got an error that package javax.servletdoes not exist.

我正在关注Head First: Servlet and JSP并且正在编写我的第一个 Servlet。
我尝试使用命令行编译它,但出现了一个package javax.servlet不存在的错误。

So far, I have set the JAVA_HOMEvariable to the value: C:\Program Files\Java\jdk1.7.0_11and the PATHvariable also to C:\Program Files\Java\jdk1.7.0_11\bin

到目前为止,我已经将JAVA_HOME变量设置为 value:C:\Program Files\Java\jdk1.7.0_11并且PATH变量也设置为C:\Program Files\Java\jdk1.7.0_11\bin

How do I get the javax.servletpackage?

我如何获得javax.servlet包裹?

Also, I have installed JDK 7 update 11after the applet bug that was being exploited.
I have both JDK Update 11and JDK Update 9installed.
Should I get rid of Update 9or is it not needed ?

另外,我JDK 7 update 11在被利用的小程序错误之后安装了。
我都JDK Update 11JDK Update 9安装。
我应该摆脱Update 9还是不需要?

Misc

杂项

Operating System:Windows 7 Home Premium 32 bit

操作系统:Windows 7 家庭高级版 32 位

What I also tried:

我也尝试过:

javac -cp .;D:\Program Files\apache-tomcat-7.0.35-windows-x86\apache-tomcat-7.0.35\lib\servlet-api.jar Ch1servlet.java

javac -cp .;D:\Program Files\apache-tomcat-7.0.35-windows-x86\apache-tomcat-7.0.35\lib\servlet-api.jar Ch1servlet.java

I tried both forward slash AND backward slash. In both the cases I got an invalid flag error.

我尝试了正斜杠和反斜杠。在这两种情况下,我都收到了无效标志错误。

回答by Ian Roberts

javac -cp .;D:\Program Files\apache-tomcat-7.0.35-windows-x86\apache-tomcat-7.0.35\lib\servlet-api.jar Ch1servlet.java

You're 99% of the way there, you just need to put some extra quotes in because the path to your servlet API jar contains spaces. Try this:

您已经完成了 99% 的工作,您只需要添加一些额外的引号,因为 servlet API jar 的路径包含空格。尝试这个:

javac -cp ".;D:\Program Files\apache-tomcat-7.0.35-windows-x86\apache-tomcat-7.0.35\lib\servlet-api.jar" Ch1servlet.java

回答by TheWhiteRabbit

It will not be because

不会是因为

  • Servlets are part of Java-EE and not Java-SE
  • You need to download and add java-ee libraries if you need to use servlets
  • Servlet 是 Java-EE 而不是 Java-SE 的一部分
  • 如果需要使用servlet,需要下载并添加java-ee库