简体   繁体   English

我的JDK中没有javax.servlet包

[英]There is no javax.servlet package in my JDK

I am following Head First: Servlet and JSP and I was writing my first Servlet. 我遵循的是Head First: Servlet and JSP并且正在编写我的第一个Servlet。
I tried to compile it using command line and I got an error that package javax.servlet does not exist. 我尝试使用命令行对其进行编译,但出现错误消息package javax.servlet不存在。

So far, I have set the JAVA_HOME variable to the value: C:\\Program Files\\Java\\jdk1.7.0_11 and the PATH variable also to C:\\Program Files\\Java\\jdk1.7.0_11\\bin 到目前为止,我已经将JAVA_HOME变量设置为以下值: C:\\Program Files\\Java\\jdk1.7.0_11 ,并且PATH变量也设置为C:\\Program Files\\Java\\jdk1.7.0_11\\bin

How do I get the javax.servlet package? 如何获得javax.servlet包?

Also, I have installed JDK 7 update 11 after the applet bug that was being exploited. 此外,在被利用的applet错误之后,我还安装了JDK 7 update 11
I have both JDK Update 11 and JDK Update 9 installed. 我同时安装了JDK Update 11JDK Update 9
Should I get rid of Update 9 or is it not needed ? 我应该摆脱Update 9还是不需要?

Misc 杂项

Operating System: Windows 7 Home Premium 32 bit 操作系统: Windows 7 Home Premium 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

I tried both forward slash AND backward slash. 我尝试了正斜线和反斜线。 In both the cases I got an invalid flag error. 在这两种情况下,我都收到无效的标志错误。

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. 您已经完成了99%的工作,只需添加一些引号,因为Servlet API jar的路径包含空格。 Try this: 尝试这个:

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

It will not be because 不会因为

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM