This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
You have a classpath setup issue, and the next point is you can save the file any where, only the generated class file should be in proper place.
I assume you have a setup of windows xp might be same in vista not very sure with tomcat server.
Step1: set the classpath
------------------------
My Computer->properties->Advanced->Environment variable
Now under user variable if there is any variable called classpath, click edit at end of the variable value put a ; paste the path of servlet-api.jar which is under lib of tomcat home for e.g.
If dont have any classpath variable , create new , variable name classpath value as follows
%classpath%;C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.14\lib\servlet-api.jar;.
Apply the settings
The mentioned path and version mentioned above may change based on your installation
Step2
-----
Compile your code.
Step3
------
Create the directory structure under tomcat. under webapps folder of tomcat home create a folder(i.e. you context root folder which will contain your web pages , servlets etc.). Under this folder create another folder called WEB-INF and under WEB-INF create another folder called classes.
Step4
------
Now copy your generated package or class file , whatever you have to this classes folder, and put the web.xml file under WEB-INF folder.
8080 is the default port of tomcat, if not reconfigured.
Most importantly if you have any ide like netbeans or myeclipse its best to work there, because it does everything for you.
Swastik
Nina Savannah
Ranch Hand
Joined: Oct 15, 2008
Posts: 35
posted
0
Thanks a lot. I have followed all the instruction. Now I am not sure how exactly the file is compiled.
I'm doing everything manually. Is what I have below what compiling is?
You compile it in the way you compile a simple java code, the only thing what you need is to setup the classpath properly so that it can locate the required packages and classes.
You still have the problem of classpath setup, what server are you using? If tomcat can you tell me the exact path of your tomcat installation.
Nina Savannah
Ranch Hand
Joined: Oct 15, 2008
Posts: 35
posted
0
Here is where Tomcat 5.0.27 is installed
C:\Tomcat5027
Java is installed in C:\j2sdk1.4.2
(There's another Java in C:\Program Files\Java\j2re1.4.2 though I am not using this one.)
Here is my classpath
.;C:\j2sdk1.4.2\bin;C:\Program Files\Java\j2re1.4.2\lib\ext\QTJava.zip;C:\Tomcat5027\common\lib\servlet-api.jar;
HelloWorld.java is saved in C:\Tomcat5027\webapps\ROOT\WEB-INF\classes\test
web.xml is saved in C:\Tomcat5027\conf, I copied it into C:\Tomcat5027\webapps\ROOT\WEB-INF\
under webapps create a folder called publications. under this folder create a folder called WEB-INF and copy your web.xml file here. Now under WEB-INF folder create a folder called classes and copy your package i.e test to this classes folder. Now restart tomcat and type the following url in browser
Yes I did what you suggested and I have now deleted web.xml in C:\Tomcat5027\webapps\ROOT\WEB-INF
so I'm left with web.xml in C:\Tomcat5027\conf
but my HelloWorld.class & HelloWorld.java is in C:\Tomcat5027\webapps\ROOT\WEB-INF\classes\test
You are probably not getting me properly are probably I am not being able to explain you properly. In tomcat rather in any web application we need to to maintain a particular directory structure. As far as tomcat is concerned we need to follow the following directory structure. Forget about that ROOT folder. The publication folder which you are saying contains your web site contents should be under webapps not under ROOT. now the publication folder should contain WEB-INF which will contain the web.xml file(web deployment desciptor). Under the same folder i.e. WEB-INF you need another folder called classes which will contain your package/or class files. So in your case test is the package which contains the servlet class file.
After making the changes please do restart your server.
Nina Savannah wrote:I'm trying to get this servlet to work but i'm getting errors.
Here is what I did:-
I added the following code to web.xml to invoke my servlet in C:\Tomcat5027\conf
Once you get your servlet to compile,
You should create a deployment descriptor specifically for your application and place it under your application's WEB-INF directory.
The global deployment descriptor (the one in tomcat/conf/) is for configuring behavior common to all applications running under Tomcat.