• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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.
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • 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.

 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • 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)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Beginning Java where compilation problems are best addressed.
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • 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: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And it isn't import java.io; It is import java.io.Something;
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!