This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Basic Servlet Compilation Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Basic Servlet Compilation Problem" Watch "Basic Servlet Compilation Problem" New topic
Author

Basic Servlet Compilation Problem

sudhir harsha
Greenhorn

Joined: Jan 23, 2006
Posts: 19
Dear Members,
I'm trying to compile "BeerSelect.java" file as mentioned below(3rd chapter in HFSJ), but it's displaying the following errors. Please suggest how to resolve this problem.

I've set CLASSPATH = E:\tomcat\Tomcat5.0\common\lib\servlet-api.jar, But still I'm getting this problem.

E:\tomcat\MyProjects\beerV1>javac -classpath E:\tomcat\Tomcat5.0\common\lib\servlet-api.jar:classes:. -d classes src\com\example\web\BeerSelect.java

src\com\example\web\BeerSelect.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
src\com\example\web\BeerSelect.java:4: package javax.servlet.http does not exist

import javax.servlet.http.*;
^
src\com\example\web\BeerSelect.java:7: cannot resolve symbol
symbol : class HttpServlet
location: class com.example.web.BeerSelect
public class BeerSelect extends HttpServlet{
^
src\com\example\web\BeerSelect.java:8: cannot resolve symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request,
^
src\com\example\web\BeerSelect.java:9: cannot resolve symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect
HttpServletResponse response)
^
src\com\example\web\BeerSelect.java:10: cannot resolve symbol
symbol : class ServletException
location: class com.example.web.BeerSelect
throws IOException , ServletException {
^
6 errors




with Thanks and Regards,
Sudhir
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
It is class path problem. Make sure you are setting it correctly.
sadasiva kumar
Ranch Hand

Joined: Oct 30, 2003
Posts: 91
I've set CLASSPATH = E:\tomcat\Tomcat5.0\common\lib\servlet-api.jar, But still I'm getting this problem


In your class path u must end with semicolon
servlet-api.jar;


SADASIVAKUMAR UTTI, SCJP1.4
A bend in the road is not the end of the road ... unless you fail to make the turn.
Chandra Sagi
Ranch Hand

Joined: May 05, 2005
Posts: 162
Your CLASSPATH should also include present directory (.\) and also to C:\Program Files\Java\jdk1.5.0_04\bin (this varies for you). This should solve your problem.

Thanks
Chandu
sudhir harsha
Greenhorn

Joined: Jan 23, 2006
Posts: 19
Dear Chandra,

I've set the CLASSPATH to present directory (.\) and also to E:\j2sdk1.4.2_10\bin . Still I couldn't able to solve the problem!
You might've noticed here that I'm using Tomcat5.0 and Jdk1.4. Is there ne problem due to the difference in version? Plz suggest.

Thanks,
Sudhir
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

I've set the CLASSPATH to present directory (.\) and also to E:\j2sdk1.4.2_10\bin . Still I couldn't able to solve the problem!


You are NOT supposed to include bin path in classpath. It has to be set in path environment variable.

set path=%path%;E:\j2sdk1.4.2_10\bin;E:\tomcat\Tomcat5.0\bin;

set classpath=%classpath%;.;E:\tomcat\Tomcat5.0\common\lib\servlet-api.jar;


You might've noticed here that I'm using Tomcat5.0 and Jdk1.4. Is there ne problem due to the difference in version? Plz suggest.


Thats OK.

Let me know how it goes.
[ March 02, 2006: Message edited by: Vishnu Prakash ]

Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
sudhir harsha
Greenhorn

Joined: Jan 23, 2006
Posts: 19
Hi,
Let me clearly explain what path I've set to PATH and CLASSPATH varables;

CLASSPATH: E:\tomcat\Tomcat5.0\common\lib\servlet-api.jar;

PATH: E:\j2sdk1.4.2_10\bin;E:\tomcat\Tomcat5.0\bin;

Thats all I did. Ne thing else to be added? Plz suggest.

Sudhir
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Which version of windows are you using?

set the path and classpath as I had suggested you.
sudhir harsha
Greenhorn

Joined: Jan 23, 2006
Posts: 19
Hi Vishnu,
I'm using Windows-2000.
I've set exactly what u mentioned, but still no luck

Sudhir
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
In window 2000/XP set the variables in

1. Right click My-Computer==>Advanced(tab)==>Environment Variables==>Click new for each one of these variables.(or)
2. Start ==> Settings ==> Control Panel ==> Sytem ==> Advanced(tab)==>Environment Variables==>Click new for each one of these variables.
sudhir harsha
Greenhorn

Joined: Jan 23, 2006
Posts: 19
Hi Vishnu,
I'm sorry for troubling U.
Ofcourse I did like that only.
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Good. You got more variables to set.

set these variables as you did before.

TOMCAT_HOME=E:\tomcat\Tomcat5.0
CATALINA_HOME=E:\tomcat\Tomcat5.0
JAVA_HOME=E:\j2sdk1.4.2_10
sudhir harsha
Greenhorn

Joined: Jan 23, 2006
Posts: 19
Hi,
Yes I Added, still same errors!
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
I think you are messing up with package directory structure while compiling.

As for as the declarations are concerned you got everything correct.
sudhir harsha
Greenhorn

Joined: Jan 23, 2006
Posts: 19
Hi Vishnu,
Solved that problem.Thanku.
Now I deployed the BeerSelect.class in the "E:\tomcat\Tomcat5.0\webapps\Beer-v1\WEB-INF\classes\com\example\web", and then I tried to run http://localhost:8080/Beer-v1/form.html. I'm getting the form but after clcking "SUBMIT" Nothing is happening!!! I mean browser not displaying ne output. I wrote DD(web.xml),form.html etc,.everything as it is mentioned in HFSJ. But Y I'm not getting the out put?? Ne Idea? Ne thing else to be done?? Plz suggest.

regards,
Sudhir
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

Solved that problem.Thanku.


Congrats




But Y I'm not getting the out put?? Ne Idea?


Use full words.

Y - why
Ne - Any


I wrote DD(web.xml),form.html etc,.everything as it is mentioned in HFSJ. But Y I'm not getting the out put?? Ne Idea? Ne thing else to be done?? Plz suggest.


Did you write the code inside the doPost() method.
sudhir harsha
Greenhorn

Joined: Jan 23, 2006
Posts: 19
Hi,
Yes ofcourse I worte. I've copied as it is from HFSJ.
Ice Penov
Ranch Hand

Joined: Apr 19, 2005
Posts: 70
Sudhir,

read this carefully :

http://www.coreservlets.com/Apache-Tomcat-Tutorial/

If you read it, and you still have deployment/compilation problems, then you're doing something wrong.

If that is the case, I have an advice for you : try again!


In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
Is Tomcat 5.5 also compatble with JAVA 1.5?
actually i am also getting the same errors as mentioned by Sudhir.

So can anyone plz tell me?

Thanks


Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Tomcat 5.5 requires JRE 5.0 by default


[My Blog]
All roads lead to JavaRanch
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
u can get complete tutorial on Tomcat installation on www.coreservlets.com
i used it it my tomacat is running fine


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Muthuvel Ramamoorthy
Greenhorn

Joined: Jun 08, 2006
Posts: 20
E:\tomcat\MyProjects\beerV1>javac -classpath E:\tomcat\Tomcat5.0\common\lib\servlet-api.jar:classes:. -d classes src\com\example\web\BeerSelect.java


for windows OS, we should use ; instead of : in between jar & classes

E:\tomcat\MyProjects\beerV1>javac -classpath E:\tomcat\Tomcat5.0\common\lib\servlet-api.jar;classes;. -d classes src\com\example\web\BeerSelect.java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Basic Servlet Compilation Problem
 
Similar Threads
Newbie question: Going through Head First Servlets & JSP book
package does not exist problem
How To Compile Servlet
Unable to import
Deploying Servlets on tomcat