Win a copy of Pragmatic AI this week in the Artificial Intelligence 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Head First Mock Exam 43  RSS feed

 
Ranch Hand
Posts: 1698
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
Bartender
Posts: 3117
259
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.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!