The Artima Developer Community
Sponsored Link

Java Answers Forum
Servlet Does have Comstructor ?

4 replies on 1 page. Most recent reply: Sep 30, 2004 6:53 AM by Samrat Bhatnagar

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Birendar S Waldiya

Posts: 21
Nickname: ebiren
Registered: Nov, 2003

Servlet Does have Comstructor ? Posted: Jun 23, 2004 4:52 AM
Reply to this message Reply
Advertisement
Hi,
Can any one clear y doubt regarding servlet .
Do servlet have the constructor??
If yes why dont ever we use them ?
When does the servlet realy get initialised and destroyed ?

thanks
rgds
Birendar S Waldiya


vijaya

Posts: 5
Nickname: vijji
Registered: Dec, 2002

Re: Servlet Does have Comstructor ? Posted: Jul 20, 2004 6:28 AM
Reply to this message Reply
Servlets doesn't have any constructors.Even if we give any constructors,it's not going to be affected.

Servlets get initiated in the init method of servlet.This method is called only once in the lifetime of the servlet.
Servlets get recieve the request from the client and send the response to the client in service method.
Servlets get destroyed in the destroy method.When we do any modification or delted the servlet from the container then ,this destory method is called.

Thanks & Regards
Vijaya.

levey baskar

Posts: 1
Nickname: levey
Registered: Aug, 2004

Re: Servlet Does have Comstructor ? Posted: Aug 16, 2004 5:14 AM
Reply to this message Reply
More over servlet instance are created by servlet container, it is using init method of servlet to initiate. So constructor is not required.

-Levey

Miroslav Pokorny

Posts: 1
Nickname: mp
Registered: Aug, 2004

Re: Servlet Does have Comstructor ? Posted: Aug 19, 2004 2:26 PM
Reply to this message Reply
All classes in Java have constructors. As with many other components Servlets use default no arguments constructors. However it is recommended that actually initialization occur within init().

Samrat Bhatnagar

Posts: 2
Nickname: ironman166
Registered: Sep, 2004

Re: Servlet Does have Constructor ? Posted: Sep 30, 2004 6:53 AM
Reply to this message Reply
We know that for any class to create its object we must have a way to instantiate it.One way is thru a constructor which must be declared PUBLIC.The reason a Servlet does not have a constructor is that whenever you are writing a Servlet you are actually adhering to servlet specification API.
We execute a servlet on a Servlet Container(which also implements the Servlet Specification) like TOMCAT.Now this is like a protocol.The container expects that the servlet has a init method which actually loads a servlet.Then consequent requests will be served by service().

Flat View: This topic has 4 replies on 1 page
Topic: cross context jsp include Previous Topic   Next Topic Topic: screen capture help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use