package javax.servlet.http does not exist but servlet-api.jar does

16,083

Solution 1

The servlet API is not part of Java SE, but of Java EE. It's not bundled with the JDK. Find the javaee jar file in your Glassfish install and put it in your compilation classpath.

Solution 2

You need servlet-api in your classpath when it is being compiled, it might be there with server but it would be available at runtime (not at compile time)

Solution 3

Make sure you have servlet-api.jar in your classpath because is not part of the standard Java SDK.

Share:
16,083
ggkmath
Author by

ggkmath

Updated on June 04, 2022

Comments

  • ggkmath
    ggkmath almost 2 years

    I've got my GlassFish 3.1.2 web server working fine with Java SE 1.6 for regular Java POJOs. The JAVA_HOME, JAVA_PATH, and JRE_HOME variables are set correctly. I'm using Linux CentOS6.2 and I'm doing all the java work from vi and the command line (e.g. no frameworks or tools like Spring, Eclipse, etc.).

    Now I want to use a Java Servlet, and I'm getting errors such as:

    package javax.servlet.http does not exist
    

    I assumed that since my environment paths are set correctly, that the servlet files would be visible to during compile. Apparently this isn't the case.

    Anyone know how to fix this error? If were to hunt around on my linux directories, what filename am I looking to find for the servlet jar file? Anyone know where this file is located starting from JAVA_HOME for JDK 1.6?

    Or, are the servlet-related files not part of jdk 1.6, and need to be downloaded installed separately?

    UPDATE:

    If I type locate servlet-api.jar from my linux prompt, it returns a path inside my GlassFish installation directories (e.g. ~/glassfish3/glassfish/modules/javax.servlet-api.jar). Thus, as mentioned below, it's part of the GlassFish installation.