• 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

object creation order by Servlet.

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the order of object created by Servlet.

1-ServletContext object

2-Servlet(class) object

3-ServletConfig object

4-Request and Response object

my question is that i read "head first Servlet" where written Request and Response object created before creating Thread.i confused.
please help me.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What has the thread to do with the objects you listed? Why are you confused?
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first of all the object creation is NOT by servlet. it is by container. as you might have read in head first servlets, a object gains/becomes servlet when its init(ServletConfig config) method completes. before init() an object is just another object. also as the book says that for becoming official card carrying servlet, it needs 2 things which are ServletContext and ServletConfig. so when a web app is deployed, the container first read the DD , creates ServletContext object, reads the context param and make pair of name-value strings and gives the reference of those strings to ServletContext. now the next part. some container initializes all the servlet as soon as the web app is deployed, some other only when a request for that particular servlet comes. i think you can configure this option in containers. whatever the option be, when the request comes, container calls default no-arg constructor of the servlet. then creates ServletConfig object and calls init(ServletConfig) method. so i you are asking about order first ServletContext, then Servlet Object(but it won't be initialized so it won't be real servlet object with all its servletness), then ServletConfig and then the real Servlet object which does all the work
 
Ritesh raushan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:first of all the object creation is NOT by servlet. it is by container. as you might have read in head first servlets, a object gains/becomes servlet when its init(ServletConfig config) method completes. before init() an object is just another object.

.

what means before init() an object is just another object.please explain.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not an accurate way to put it. The servlet isn't ready to accept requests before its init() lifecycle method is called, but the object doesnt magically change into something else when init() is called.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ritesh raushan wrote:

gurpeet singh wrote:first of all the object creation is NOT by servlet. it is by container. as you might have read in head first servlets, a object gains/becomes servlet when its init(ServletConfig config) method completes. before init() an object is just another object.

.

what means before init() an object is just another object.please explain.



sorry for creating the confusion. as Bear Sir, has said that until init() method of servlet is called , it is NOT ready to serve your requests. put in other words servlet is not initialized. as servlet has to be initialized before it can call service() method and serve the client/users/request.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet doesn't create any of those objects. They are all created by the servlet container (Tomcat, Websphere, or whatever).

You need a config to create the context. You need a context to initialize a servlet instance. Request and Response are created by the request processing subsystem which then invokes the servlet service() method (which in turn may invoke doGet, doPost, or whatever).
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Servlet doesn't create any of those objects. They are all created by the servlet container (Tomcat, Websphere, or whatever).

You need a config to create the context. You need a context to initialize a servlet instance. Request and Response are created by the request processing subsystem which then invokes the servlet service() method (which in turn may invoke doGet, doPost, or whatever).




isn't it the other way around i.e. we need context to create a config since context is created at web-module deployment and it is one per webapp per jvm .
reply
    Bookmark Topic Watch Topic
  • New Topic