File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes What values initialized in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "What values initialized in servlet" Watch "What values initialized in servlet" New topic

What values initialized in servlet

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
What will happen inside init() in servlet. my interviewer asked servlet lifecycle. i said "once servlet is loaded in to memory init() will be called which performs servlet initialization " . Again interview asked what values will be initialized . what is difference between init() and init(ServletConfig config).
Amit Vinod Dali
Ranch Hand

Joined: Apr 14, 2010
Posts: 42
GenericServlet with 2 init methods
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
sorry still am not clear
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
init() can be tipically called when the server starts or when the servlet is first called, before you handle the request. The server admin or the web application admin can confgure the moment in which method is called.

The only thing that you can count on is that init() is executed before the servlet executes its first request.

You are right, init() is usually called to perform servlet initialization.

About init(ServletConfig config): It's called by the container so you tipically should not override it.

As you can see from the documentation of GenericServlet class, the method init(ServletConfig config) receives the ServletConfig object config, that contains configuration information for your servlet

Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 234
Rajendra Prakash wrote:sorry still am not clear

Please Rajendra have a look here

God Gave Me Nothing I Wanted, He Gave Me Everything I Needed.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

Please check the FAQ before posting questions.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: What values initialized in servlet
jQuery in Action, 3rd edition