Life Cycle of servlets?

Answer Posted / shakir khan

javax.servlet.Servlet interface defines 3 methods known as
life cycle.
Servlet intialisation takesplace every first time,it
receives a request and remains in memory till times out or
server shutdown

When first request came in for a servlet,servlet invoke
init() only once.

public void init(ServletConfig config)
{
}
Thereafter if any user wants requet,it will directly
executes the service().

public void service(ServletRequest req,ServletResponse res)
throws servletException,IOException
{
}
When server wants to remove the servlet from pool ,it will
executes the destroy().

public void destroy()
{
}

Is This Answer Correct ?    14 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is servlet used?

688


What are the exceptions thrown by servlets? Why?

625


What is the directory structure of a war file?

715


How many servlet objects are created?

567


How do we call one servlet from another servlet?

594






Why is httpservlet declared abstract?

586


What are the benefits of using servlet over cgi?

584


How do you create a cookie using servlet?

581


What are the uses of servlets?

624


What is cgi and what are its drawbacks?

558


Is servlet a controller?

577


Once the destroy() method is called by the container, will the servlet be immediately destroyed? What happens to the tasks(threads) that the servlet might be executing at that time?

782


What is servlet and how it works?

508


How to notify an object in session when session is invalidated or timed-out?

635


How do you configure a centralized error handler in servlets?

537