• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

'package javax.servlet does not exist' error is coming

 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am using Tomcat 7.0 and java jdk1.7.0

I am not using any IDE and trying to compile the servlets through command prompt itself.

The environment variables i have set are as follows:
CLASS: C:\Program Files\Java\jdk1.7.0\lib;
CLASSPATH: C:\Program Files\Apache Software Foundation\Tomcat 7.0\common\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\commons-fileupload-1.2.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\commons-io-1.3.2.jar;C:\Program Files\Java\jdk1.7.0\bin;C:\Program Files\Java\jre7\bin;

JAVA_HOME: C:\Program Files\Java\jdk1.7.0;

Path: C:\Program Files\Java\jdk1.7.0\bin;

when i am trying to compile servlet program following error is coming

C:\>cd C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\userregist
er\WEB-INF\classes

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\userregister\WEB-
INF\classes>javac NewServlet.java
NewServlet.java:1: error: cannot find symbol
import java.io;
^
symbol: class io
location: package java
NewServlet.java:2: error: package javax.servlet does not exist
import javax.servlet.*;
^
NewServlet.java:3: error: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
NewServlet.java:4: error: cannot find symbol
public class NewServlet extends HttpServlet {
^
symbol: class HttpServlet
NewServlet.java:5: error: cannot find symbol
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
^
symbol: class HttpServletRequest
location: class NewServlet
NewServlet.java:5: error: cannot find symbol
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
^
symbol: class HttpServletResponse
location: class NewServlet
NewServlet.java:6: error: cannot find symbol
throws ServletException, IOException {
^
symbol: class ServletException
location: class NewServlet
NewServlet.java:6: error: cannot find symbol
throws ServletException, IOException {
^
symbol: class IOException
location: class NewServlet
8 errors

Please help me.
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is class environment variable, never heard of this before?

Now coming to your classpath variable

C:\Program Files\Apache Software Foundation\Tomcat 7.0\common\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\commons-fileupload-1.2.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\commons-io-1.3.2.jar

Make sure the above paths are correct, and the following two C:\Program Files\Java\jdk1.7.0\bin;C:\Program Files\Java\jre7\bin; should not be under classpath. The last two are Path environment variable.

 
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ClassPath Variable is creating a problem.

Keeping it as simple as possible:

Remove Class and ClassPath variables from environment variables. (Your "path" variable is alright)
Put servlet-api.jar pear to your servlet class.
and compile with "javac -cp .;servlet-api.jar YourServlet.java" (Considering that you only need a servlet-api.jar to compile your code, as it can be seen from the errors)
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to Beginning Java where compilation problems are best addressed.
 
Marshal
Posts: 73979
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please work out where the javax.servlet package is supposed to be. You may have to install J2EE because I can't find it in the standard API documentation.
 
Campbell Ritchie
Marshal
Posts: 73979
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And it isn't import java.io; It is import java.io.Something;
 
Campbell Ritchie
Marshal
Posts: 73979
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic