aspose file tools*
The moose likes Servlets and the fly likes package javax.servlet. does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "package javax.servlet. does not exist" Watch "package javax.servlet. does not exist" New topic
Author

package javax.servlet. does not exist

Jayanath
Greenhorn

Joined: May 21, 2004
Posts: 10
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

Joined: Apr 26, 2004
Posts: 9
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

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jayanath
Greenhorn

Joined: May 21, 2004
Posts: 10
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

Joined: Apr 14, 2004
Posts: 10336

Open the jar file up and make sure the package is there.
Jon Entwistle
Ranch Hand

Joined: Feb 20, 2003
Posts: 118
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


SCJD, SCEA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package javax.servlet. does not exist
 
Similar Threads
How to test my servlet
New to servlets
HelloWorld Servlet compilation errors
Servlet HelloWorld problem
Package not found error on running servlet !