Bookmark Topic Watch Topic
  • New Topic

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

 
srinivas pola
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 15355
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
srinivas pola
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Report post to moderator
I could solve the problem
Thanks Jesper
 
srinivas pola
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 378
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have tried by removing 'classes' from the servlet-name. But i'm still facing the same problem...

Please help me out...
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
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".
 
srinivas pola
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Report post to moderator
yes i have a web folder inside classes...

its like WEB-INF\classes\web\BeerSelectAction.java
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Report post to moderator
Yaa.. The servlet is in 'web' folder
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Next time, please don't duplicate threads :
http://www.coderanch.com/t/178072/java-Web-Component-SCWCD/certification/Help-me-solve-package-javax
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
 
Campbell Ritchie
Sheriff
Pie
Posts: 49379
62
  • Mark post as helpful
  • send pies
  • Report post to moderator
I hadn't noticed, but now somebody has mentioned it, I am closing this thread as a duplicate.
 
    Bookmark Topic Watch Topic
  • New Topic