Link to home
Start Free TrialLog in
Avatar of malli143
malli143Flag for India

asked on

How to run my servlets using tomcat 5.0

Hi

How do I run my servlet programs in Tomcat 5.0. I have done the following as of now

1. I hace installed Tomcat 5.0 successfully. If i give 'http://localhost:8080/" in my browser i am getting the tomcat page and hence i can say tomcat is running

2. I installed j2sdk1.4.2_02 and I compiled my servlet successfully.

Now I have the class file of my servlet and I don't know how to run this servlet using tomcat 5.0.
I put this class file in webapps/ROOT/WEB-INF/classes and tried to run from the browser. But it didn't work.

Can any one help me on this



Chandu

Avatar of Mayank S
Mayank S
Flag of India image

Give an entry for this servlet in web.xml
or alternately (a bad way), use: http://localhost:8080/servlet/YourServletClassName - but it might not be allowed on all versions of Tomcat.
have u setup the CLASSPATH variable.
You should add to your classpath the servlet.jar and the "." (current directory)
Ex: CLASSPATH=.;tomcat-install-dir/common/lib/servlet.jar
Also you should uncomment the lines in the tomcat-install-dir/conf/web.xml that say: <servlet-mapping>
I guess Tomcat also comes with a setclasspath batch file - you can make use of that too, if its a class-path problem.
Avatar of Ovi
Ovi

Look at the servlet examples in Tomcat and follow web.xml file there. Should work.
Avatar of malli143

ASKER

Also you should uncomment the lines in the tomcat-install-dir/conf/web.xml that say: <servlet-mapping>
 if I try to modify this , tomcat is not starting
Can you post the content from your web.xml file? The entire part from <servlet-mapping> to </servlet-mapping>, if commented, needs to be uncommented. And you need to add an entry for your Servlet in that file.

Alternatively (just for testing), you can use the second approach which I had suggested earlier.

Mayank.
ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial