Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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

 
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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
 
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...
 
Rancher
Posts: 43011
76
  • 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: 43011
76
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • 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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora 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: 2856
10
Firefox Browser Fedora 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: 2856
10
Firefox Browser Fedora Java
 
Marshal
Posts: 65407
248
  • Mark post as helpful
  • send pies
  • Report post to moderator

Originally posted by Amit Ghorpade:


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

I hadn't noticed, but now somebody has mentioned it, I am closing this thread as a duplicate.
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!