Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic Servlet Compilation Problem

 
sudhir harsha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is class path problem. Make sure you are setting it correctly.
 
sadasiva kumar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
sudhir harsha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of windows are you using?

set the path and classpath as I had suggested you.
 
sudhir harsha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishnu,
I'm using Windows-2000.
I've set exactly what u mentioned, but still no luck

Sudhir
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishnu,
I'm sorry for troubling U.
Ofcourse I did like that only.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Yes I Added, still same errors!
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Yes ofcourse I worte. I've copied as it is from HFSJ.
 
Ice Penov
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat 5.5 requires JRE 5.0 by default
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u can get complete tutorial on Tomcat installation on www.coreservlets.com
i used it it my tomacat is running fine
 
Muthuvel Ramamoorthy
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic