File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes new to servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "new to servlets" Watch "new to servlets" New topic

new to servlets

sudharshan tettu
Ranch Hand

Joined: Jul 17, 2006
Posts: 126
I am pretty new to servlets.I installed tomcat and compiled successfully a servlet.I placed the class file insdie web-inf/classes
I dont know what all the configuration I should do before ,runnin a servlet successfully on TOMCAT.
Please guide me in getting familar with workin servlets on Tomcat
nelson christos
Ranch Hand

Joined: Aug 08, 2006
Posts: 57
you have to create the web.xml file so that your servlet can be mapped to the name specified in the browser

i think therefore i am
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
Originally posted by sudharsan tettu:
I am pretty new to servlets.

Simple Servlet Examples by Ben Souther are good for newbies. Just check them out!

My blood is tested +ve for Java.
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hello Sudharsan ,

Any Servlet has 3 parts of getting it working with Tomcat or any Application Server you are using. I am not sure about other application servers, However the question in place is of Tomcat so i would be best able to help you.

The 3 parts which i am talking about are

1) Compiling - Which you have done till now.
2) Deployment - What Nelson is Talking about
3) Execution - which is explained below in part 3.

The first part is already completed by you. Now , As Nelson said , You need to create a web.xml file which is more formally called as an Deployment Descriptor. Its called so because Every Deployment information about your servlets or any other Context Related information is entered here. So, Deployment is very simple

For the servlet which you have Compiled , Add an entry in web.xml file, Make sure when you name this file, It is web.xml and not web.xml.txt. This file will be situated in your Application's WEB-INF directory.

Entry should be something like this :

<servlet-name>ANY NAME YOU WISH</servlet-name>
<servlet-class>YOUR SERVLET CLASSNAME</servlet-class>
<servlet-name>SHOULD BE THE SAME NAME DEFINED IN ABOVE <servlet-name element>

<load-on-startup> element is the element of web.xml which loads the servlet instance in the memory so that the first request to the client also is fast. For more information on web.xml , follow this WEB.XML Description

Also if your servlet is defined in a package then the <servlet-class> element should contain the packagename.YourClassName , So it would be something like


3) Executing the Servlet is as simple as running a normal file on LocalHost.
it would be something like :


Hope this helps you , Any further help , please get in touch with us again. We here at Ranch love helping our fellow Ranchers !

Best Regards ,
Yogendra Joshi

Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
sudharshan tettu
Ranch Hand

Joined: Jul 17, 2006
Posts: 126
ya its working ..thanks for your replies... and one more doubt is like ..does it work ,just copy and pasting a war file inside web-apps and just calling it...else should we configure it anywhere in deployment descriptors???
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

There is a deployment descriptor inside each war file.
Once you drop it in the webapps directory, Tomcat will uncpack it and deploy it. It will create a folder with the same name as the war file.
Look in the WEB-INF directory of the application for the deployment descriptor (web.xml)

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: new to servlets
jQuery in Action, 3rd edition