Sunday, September 12, 2010

Servlets

Servlets are replacing CGI script at most enterprise computing. They both perform similar operations of creating and displaying HTML pages dynamically. The basic differences between the two:

  • CGI - Platform dependent, hence they cannot utilize server's capabilities; spawns new process for every request, hence resource intensive;
  • Servlets - Since written in Java they can be executed in servers without any modifications as per "write once, run anywhere"; spawns new threads within the server process, hence lite weight.
Lifecycle of servlets:

  • init() - initializes the servlet
  • service(ServletRequest , ServletResponse) - all url's access this method and here we delegate to other service methods of form doXXX(HttpServletRequest , HttpServletResponse)
  • destroy() - destroys the servlet

No comments: