wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes help me solve 'package javax.servlet does not exist' error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

help me solve 'package javax.servlet does not exist' error

srinivas pola
Greenhorn

Joined: Jul 18, 2008
Posts: 24
Hi,

I am using tomcat6 and jdk1.5
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_PATH - C:\jdk1.5\lib;C:\tomcat6\lib\servlet-api.jar;C:\tomcat6\lib\jsp-api.jar;C:\tomcat6\webapps
JAVA_HOME - C:\jdk1.5
Path - C:\jdk1.5\bin;C:\jdk1.5;C:\jdk1.5\jre\bin\server

When i'm trying to compile the servlet i'm getting this error

C:\tomcat6\webapps\HeadFirst\WEB-INF\classes\web>javac BeerSelectAction.java
BeerSelectAction.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
BeerSelectAction.java:4: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
BeerSelectAction.java:7: cannot find symbol
symbol: class HttpServlet
public class BeerSelectAction extends HttpServlet {
^
BeerSelectAction.java:9: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelectAction
public void doPost(HttpServletRequest request,
^
BeerSelectAction.java:10: cannot find symbol
symbol : class HttpServletResponse


Please help me solve this error.

Thanks in advance.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

The error is here:

CLASS_PATH - C:\jdk1.5\lib;C:\tomcat6\lib\servlet-api.jar;C:\tomcat6\lib\jsp-api.jar;C:\tomcat6\webapps

The environment variable should be named CLASSPATH, not CLASS_PATH with an underscore in it.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
srinivas pola
Greenhorn

Joined: Jul 18, 2008
Posts: 24
I could solve the problem
Thanks Jesper
srinivas pola
Greenhorn

Joined: Jul 18, 2008
Posts: 24
now i'm facing another problem... :roll:

When i try to run the servlet i'm getting noclassdefinitionfound exception..

Here is my xml file:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>classes.web.BeerSelectAction</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>


The servlet i'm trying to run:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class BeerSelectAction extends HttpServlet {

public void doPost(HttpServletRequest request,
HttpServletResponse response) throws
IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");

String c = request.getParameter("color");
out.println("<br>Got beer color" +c);
}
}

Please help me out.
Thanks in advance
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
Just a lucky guess..

try web.BeerSelectAction instead of classes.web.BeerSelectAction in servlet-class

What I am thinking of here is that the package of your servlet class should not include the .....\WEB-INF\classes folder..
srinivas pola
Greenhorn

Joined: Jul 18, 2008
Posts: 24
I have tried by removing 'classes' from the servlet-name. But i'm still facing the same problem...

Please help me out...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41600
    
  55
Do you have a "package web;" statement in the source code that you didn't post? If not, then the servlet-class will just be "BeerSelectAction".


Ping & DNS - my free Android networking tools app
srinivas pola
Greenhorn

Joined: Jul 18, 2008
Posts: 24
yes i have a web folder inside classes...

its like WEB-INF\classes\web\BeerSelectAction.java
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41600
    
  55
So the answer to the question "Do you have a 'package web;' statement in the source code that you didn't post?" is "yes"?
srinivas pola
Greenhorn

Joined: Jul 18, 2008
Posts: 24
Yaa.. The servlet is in 'web' folder
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Next time, please don't duplicate threads :
http://www.coderanch.com/t/178072/java-Web-Component-SCWCD/certification/Help-me-solve-package-javax


[My Blog]
All roads lead to JavaRanch
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Originally posted by srinivas pola:
Yaa.. The servlet is in 'web' folder


Looks like you are not getting what Ulf has asked.
He means : Do you have any statement like

in your code for the servlet.


SCJP, SCWCD.
|Asking Good Questions|
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

And please use code tags while posting code, unformatted code is not only difficult to read, but also results in less response for your post. Read this for more information.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Originally posted by Christophe Verre:
Next time, please don't duplicate threads :
http://www.coderanch.com/t/178072/java-Web-Component-SCWCD/certification/Help-me-solve-package-javax


Another one :
http://www.coderanch.com/t/412017/java/java/NoClassDefFoundError-while-running-servlet
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
I hadn't noticed, but now somebody has mentioned it, I am closing this thread as a duplicate.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help me solve 'package javax.servlet does not exist' error