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

error with compiling servlet

 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I installed tomcat3.3 successfully. It is is properly starting. But I don't understand where we should save servlet and how to compile it?
I saved my first servlet on C:\ and then compiled it as
c:\javac helloworld.java
But it is giving error as package doesn't exist and cann't resolve the symbol
my classpath and path is as follows:
set TOMCAT_HOME=c:\tomcat3.3.1a
set JAVA_HOME=C:\jdk1.3
set PATH=c:\jdk1.3\bin;
set CLASSPATH= .;c:\jdk1.3\jre\lib\rt.jar;
set CLASSPATH=.;C:\tomcat3.3.1a\lib\common\servlet.jar;C:\tomcat3.3.1a\lib\common\jasper-runtime.jar;%CLASSPATH%
please help
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dhanashree,
check dir.structure in your tomcat ,I guess it must be
CLASSPATH=.;c:\tomcat3.3.1a\common\lib\servlet.jar instead of
set CLASSPATH=.;C:\tomcat3.3.1a\lib\common\servlet.jar;C:\tomcat3.3.1a\lib\common\jasper-runtime.jar;%CLASSPATH%

and no need of jasper-runtime.jar
after you compile your servlet successfuly,put the class file in
c:\tomcat3.3.1a\webapps\yourcontext\web-inf\servlets directory
------------------------------
well as per my knowledge we have tomcat 5 to use,then what is your need to install 3.3.1a
cheers
Praful
[ November 19, 2003: Message edited by: Praful Thakare ]
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check dir.structure in your tomcat ,I guess it must be
CLASSPATH=.;c:\tomcat3.3.1a\[b]common\lib\
servlet.jar instead of
set CLASSPATH=.;C:\tomcat3.3.1a\lib\common\servlet.jar;C:\tomcat3.3.1a\lib\common\jasper-runtime.jar;%CLASSPATH%

and no need of jasper-runtime.jar
after you compile your servlet successfuly,put the class file in
c:\tomcat3.3.1a\webapps\yourcontext\web-inf\servlets directory
[/b]
____________________________________________________________________________
No it is c:\tomcat3.3.a\lib\common\servlet.jar only
and i removed the other jar file as per ur instruction but still no change
____________________________________________________________________________

well as per my knowledge we have tomcat 5 to use,then what is your need to install 3.3.1a

---------------------------------------------------------------------------
This is cz yesterday only i bought a new Marty Hall's book. And i am new to servlets So i worked as per his instructions only . That set nothing else

so plz help me out of this
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please paste the error
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the program:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class helloworld extends HttpServlet{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,IOException{
PrintWriter out = response.getWriter();
out.println("hello world");
}
}
______________________________________________________________
package javax.servlet does not exist
import javax.servlet.*;
^
helloworld.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
helloworld.java:4: cannot resolve symbol
symbol : class HttpServlet
location: class helloworld
public class helloworld extends HttpServlet{
^
helloworld.java:5: cannot resolve symbol
symbol : class HttpServletRequest
location: class helloworld
public void doGet(HttpServletRequest request,
^
helloworld.java:6: cannot resolve symbol
symbol : class HttpServletResponse
location: class helloworld
HttpServletResponse response)
^
helloworld.java:7: cannot resolve symbol
symbol : class ServletException
location: class helloworld
throws ServletException,IOException{
^
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also when i tried http://localhost:8080
it is giving page not forund
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dhanashree,
we get these errors only if classpath dont contain servlet.jar;
so i still feel there is something wrong in your classpath.
try one of following thing
change name of your tomcat directory from tomcat3.3.1a to tomcat
then open command prompt type set classpath=c:\tomcat\lib\common\servlet.jar.
then compile your program.
Also recheck that servlet.jar file is present in tomcat\lib\common.
do let me know the results
Praful
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add the location of servlet.jar to your classpath, or put servlet.jar in your "jdk directory\jre\lib\ext\" folder. The compiler will automatically find it in this directory.
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

we get these errors only if classpath dont contain servlet.jar;
so i still feel there is something wrong in your classpath.
try one of following thing
change name of your tomcat directory from tomcat3.3.1a to tomcat
then open command prompt type set classpath=c:\tomcat\lib\common\servlet.jar.
then compile your program.
Also recheck that servlet.jar file is present in tomcat\lib\common.
do let me know the results

I changed the name of file but still it is giving same error
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Add the location of servlet.jar to your classpath, or put servlet.jar in your "jdk directory\jre\lib\ext\" folder. The compiler will automatically find it in this directory.

___________________________________________________________________________
i changed as per ur suggetions so now my classpath is
set TOMCAT_HOME=c:\tomcat
set JAVA_HOME=C:\jdk1.3
set PATH=c:\jdk1.3\bin;
set CLASSPATH= .;c:\jdk1.3\jre\lib\rt.jar;
set CLASSPATH = .;C:\jdk1.3\jre\lib\servlet.jar;%CLASSPATH%
then i compiled it
c:\javac helloworld.java
but still giving those errors
plz help
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PLEASE HELP
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The %java_home% and the %tomcat_home% environment variables look fine. The PATH variable should look this or . You should append the java\bin and tomcat\bin directory to your already PATH env variable and then set it.
I would recommend that you put the servlet.jar file in the folder until you get comfortable with setting the CLASSPATH variable at the command line. Once you do that remove the CLASSPATH variable from your AUTOEXEC.BAT file by either deleting all references to it or commenting it out by placing "REM" in from of it. I would recommend you comment it out, you may want to set it later. Then reboot your PC.
Once you do all that, just type at the command line. Hopefully it will compile
Also you stating
Also when i tried http://localhost:8080
it is giving page not forund

Did you startup tomcat? If not tomcat can be started by typing at the command line: or going to the tomcat\bin directory and executing startup.bat.
I hope I didn't miss anything.
Craig.
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii
Atlast i got it. It was really a silly mistake.
I gave a space between "=" and "."
It should be like this
set CLASSPATH=.;c:\-----
There should not be any space bet = and . operator.
Thanx a lot to all of u for helping me
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic