Thursday, 16 July 2015

Servlet's Introduction

In core java you have learned the Applet programming which uses the java.applet.Applet class to create an applet and init, start, stop and destroy method of Applet class to execute the applet with applet container. As you know we can run the applet on the web browser but the applet is client side programming. If we want to do the server side programming with java we need to go for the servlet. As you have learned in the first chapter J2EE, API’s servlet is one of the J2EE API’s which is used to create dynamic web pages using java as programming language. If we want to run the servlet we require the web container to execute the servlet file.


Initially in the early days CGI ( Common Gateway Interface) was used to write the server side scripting or to create the dynamic web pages with most of the languages like C, C++, and also with java. But when user request for something; server needs to create the different process for each and every HTTP request of the client. After giving the response to the client and executing the CGI script server should release the system resources.

It takes much execution time at the cost of the performance. It was also expensive to open and close the database connection for each client. In addition it is platform dependent. To overcome these limitations servlet was introduced by Sun Microsystems.

Advantages of Servlet over CGI

  • Performance:
    • Its performance is better than the CGI because it is not necessary to create the separate process to handle each HTTP request, it executes within the address space of web server. So it saves the memory resources and makes performance better than CGI.
  • Platform independent:
    • A number of web servers from different vendors supports servlet API. It is written in java so program developed for this API can be run on any environment without recompilation.
  • Security:
    • Servlet run under the JVM and it is secured using java sandbox. It is also using Java Security Manager. It is server side component, so it inherits the security provided by the web server.

No comments:

Post a Comment