package javax.servlet.http does not exist
On *nix, try:
javac -cp $CLASSPATH:$CATALINA_HOME/lib/servlet-api.jar Filename.java
Or on Windows, try:
javac -cp %CLASSPATH%;%CATALINA_HOME%\lib\servlet-api.jar Filename.java
Your CLASSPATH variable does not point to the directory containing the javax classes. The CLASSPATH variable specifies where the java compiler should look for java class file resources. If it does not know to look in the javax directory, then it will never find the file(s) you are after.
If you are working with maven project, then add following dependency to your pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
If you're using the command console to compile the servlet, then you should include Tomcat's /lib/servlet-api.jar
in the compile classpath.
javac -cp .:/path/to/tomcat/lib/servlet-api.jar com/example/MyServlet.java
(use ;
instead of :
as path separator in Windows)
If you're using an IDE, then you should integrate Tomcat in the IDE and reference it as target runtime in the project. If you're using Eclipse as IDE, see also this for more detail: How do I import the javax.servlet API in my Eclipse project?