Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Head First Mock Exam 43  RSS feed

 
Ranch Hand
Posts: 1703
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What is true about the lifecycle of a servlet?
Option A. The service() method is the first method invoked by the container when a new request is received.
....


I think this option is correct, but the given answer says it is not correct.
Explanation:


Option A : the init() method is invoked first.


My reason:
I assumed the servlet has been instantiated and initialized(), when a new request is received,
the container calls service() method which invokes the doGet, doPost or other do methods depending on the request's action.
 
Creator of Enthuware JWS+ V6
Posts: 3189
276
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I assumed the servlet has been instantiated and initialized(), when a new request is received


No, that is not always the case:

Form the Servlet specs:

The loading and instantiation can occur when the container is started, or delayed until the container determines the servlet is needed to service a request.

and

After the servlet object is instantiated, the container must initialize the servlet before it can handle requests from clients. Initialization is provided so that a servlet can read persistent configuration data, initialize costly resources (such as JDBC™ API based connections), and perform other one-time activities. The container initializes the servlet instance by calling the init method of the Servlet interface with a unique (per servlet declaration) object implementing the ServletConfig interface.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!