written 8.3 years ago by | • modified 8.3 years ago |
Mumbai University > Information Technology > Sem 4 > Web Programming
Marks: 10M
Year: May 2015
written 8.3 years ago by | • modified 8.3 years ago |
Mumbai University > Information Technology > Sem 4 > Web Programming
Marks: 10M
Year: May 2015
written 8.3 years ago by |
Servlet Life cycle methods:
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 init() method :
The init method definition looks like this:
public void init() throws ServletException {
// Initialization code...
}
The service() method :
The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate. Here is the signature of this method:
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.
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.
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Servlet code
}
The destroy() method :
After the destroy() method is called, the servlet object is marked for garbage collection. The destroy method definition looks like this:
public void destroy() {
// Finalization code...
}