• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

new to servlets

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
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
Thanks
Sudarsan.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have to create the web.xml file so that your servlet can be mapped to the name specified in the browser
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 :

<web-app>
<servlet>
<servlet-name>ANY NAME YOU WISH</servlet-name>
<servlet-class>YOUR SERVLET CLASSNAME</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SHOULD BE THE SAME NAME DEFINED IN ABOVE <servlet-name element>
<url-pattern>/servlet/YOURSERVLETNAME</url-pattern>
</servlet-mapping>
</web-app>

<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

<servlet-class>yogendra.MyServlet</servlet-class>

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

http://localhost:8000/YOURAPPNAME/servlet/SERVLETCLASSNAME

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
 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
I think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic