• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package javax.servlet. does not exist

 
Jayanath
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
When I tryed to compile this simple servlet,

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}

it gave me the error-> package javax.servlet does not exist

Im using
j2sdk1.4.0
Tomcat4.1
CLASSPATH=C:\Tomcat4.1\common\lib\servlet.jar
Whats wrong with this..
I went through the web befor submit this,there were plenty of occurences of the same problem but the answers were same as "Check your classpath" for most of the times.

Pls help me on this.
Thanx in advance for any help.
best regs,
Jayanath.
 
Himanshu Pathak
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats right.
this is a problem with the classpath only.
you didnt specified how are you compiling your files.
i mean are you doing it at command prompt or with any IDE.

if you are doing it on command line make sure the jar file exist in your classpath.

echo %classpath% (for windows)
echo $CLASSPATH (LINUX)

if you are using an IDE make sure that you added the jar file for the project settings.


Himanshu.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I went through the web befor submit this,there were plenty of occurences of the same problem but the answers were same as "Check your classpath" for most of the times.

The answers you found were correct. It is a classpath problem. Since your classpath points to servlet.jar (which contains said package) I'd check whether you are actually using the classpath when you compile this class - it could be being overwritten if you are using an ant file for example, or ignored by whatever IDE you have. An of course, I'd check servlet.jar hasn't been corrupted.
 
Jayanath
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pathak,
Im using the command prompt and when I type echo %classpath% it displayed the servlet.jar file in the path.
My OS is WinXP & Ive used environment variable setting to add the servlet.jar file into the classpath.
But problem is still there.

Paul,How do I verify whether my servlet.jar file is corrupted or not.Pls let me know.

Thanx for your help.

Jayanath.

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Open the jar file up and make sure the package is there.
 
Jon Entwistle
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It is very unlikely that your servlet.jar is corrupted - I would first check very carefully the spelling and syntax of your classpath variable and ensure it matches the same position on file. Better still post the entire classpath here.

As far as checking out the servlet jar, the syntax is similar to tar:

from the command line in the directory holding the file:

jar xvf servlet.jar


Jon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic