Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

package javax.servlet.http does not exist [duplicate]

Tags:

java

servlets

I have the jre7 and jdk1.7.0 installed along with the Tomcat 7.0 but it shows this error. servlet.http is not the only one that "does not exist", there are also other (servlet.) components.

Can anybody help me with this?

UPDATE: This error occurs when I try the follow command: javac -classpath servlet-api.jar WebTest.java

like image 603
Andrew Avatar asked Oct 05 '11 18:10

Andrew


People also ask

How do I fix javax servlet HTTP does not exist?

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. If you're using an IDE, then you should integrate Tomcat in the IDE and reference it as target runtime in the project.

What is javax servlet http package?

The javax. servlet. http package contains a number of classes and interfaces that describe and define the contracts between a servlet class running under the HTTP protocol and the runtime environment provided for an instance of such a class by a conforming servlet container.

Where is javax servlet package?

It contains, among others, the files /usr/share/java/servlet-api-2.5. jar and /usr/share/java/jsp-api-2.1. jar , which are the servlet and JSP libraries you need.

How do I import the javax servlet API in my Netbeans project?

Right-click your project, click on properties->Java Build path->Libraries tab->click Add External JARs->Browse for servlet-api. jar and select it->click OK to update the build path. Right-click the project, click properties->Java Build Path->click ADD JARs->find servlet-api.


4 Answers

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>
like image 186
Swalih Avatar answered Oct 18 '22 00:10

Swalih


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?

like image 19
BalusC Avatar answered Oct 18 '22 00:10

BalusC


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.

like image 18
ashutosh raina Avatar answered Oct 17 '22 22:10

ashutosh raina


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
like image 5
roartechs Avatar answered Oct 17 '22 23:10

roartechs