Documente Academic
Documente Profesional
Documente Cultură
when the Servlet container loads Servlet, and ends when the
container is closed down Servlet. A servlet container is the part of
a web server or an application server that controls a Servlet by
managing its life cycle.
A servlet life cycle can be defined as the entire process from its
creation till the destruction. The following are the paths followed
by a servlet.
The servlet is initialized by calling the init() method.
The servlet calls service() method to process a client's request.
The servlet is terminated by calling the destroy() method.
Finally, servlet is garbage collected by the garbage collector of the
JVM.
Learn Professional Java Training in Chennai @ Greens
Technologys.
The init() Method
The init technique is called just once. It is called just when the
servlet is made, and not required any client asks for thereafter. In
this way, it is utilized for one-time instatements, similarly as with
the init strategy for applets.
Each time the server gets a demand for a servlet, the server brings
forth another string and calls benefit. The administration()
technique checks the HTTP ask for type (GET, POST, PUT,
DELETE, and so forth.) and calls doGet, doPost, doPut, doDelete,
and so forth strategies as proper.
The service method definition looks like this:
public void service(ServletRequest request,
ServletResponse response)
throws ServletException, IOException{
}
The doGet() Method
A GET request results from a normal request for a URL or from an
HTML form that has no METHOD specified and it should be
handled by doGet() method.
The doget method definition looks like this:
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Servlet code
}
The doPost() Method
A POST request results from an HTML form that specifically lists
POST as the METHOD and it should be handled by doPost()
method.
The dopost method definition looks like this:
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Servlet code
}