Showing posts with label Servlet. Show all posts
Showing posts with label Servlet. Show all posts

Tuesday, December 13, 2011

Advantages of Servlets over CGI

  • Servlets are server side components that provides a mechanism for developing server web applications  for server side.
  • Earlier CGI was developed to provide server side Capabilities to the web applications, But due to its Performance, Scalability and Reusability  issues, Servlets are preferred.
  • Java Servlets overcome all the issues of CGI ( Common Gateway Interface ).
  • Servlets are built from ground up using Sun's Write one run anywhere technology, java servlets provide excellent framework for server side processing.
  • Web Developers can create fast & efficient server side applications using java servlets and can run it on any web server which is servlet compatible.
  • servlets run entirely inside the java Virtual Machine.
  • since servlets runs on server side, it does not check for Browser Compatibility.
Servlets mainly have 5 Advantages over CGI, they are

1) Platform Independent

  • Platform Independence plays a major in the field where there are numerous number of web servers available to choose from.
  • Servlets are written entirely in java, due to which they are platform independent.
  • Servlets can run on any servlet enabled web-server.
Ex: web applications developed in windows machine running java web server, can easily run the same on apache web server ( if Apache server is installed ), without any modification or compilation of code.

2) Performance

  • Due to interpreted nature of java, programs written in java are slow. But java servlets run very fast. it is because the way servlets run on web server.
  • For any program Initialization takes significant amount of time in its life cycle. But in case of servlets initialization takes place only once when it receives the first request & remains in memory till times out or server shuts down's.
  • Once servlet is initialized & loaded, to handle a new request it simply creates a new thread and runs service method of servlet.
  • In case of CGI scripts, always a new process should be created to serve a request.
3) Extensibility

  • Servlets are developed in java which is robust, well-designed & Object oriented language which can be extended or polymorphed into a new object
  •  java servlets take all java's advantages to provide the ideal solution.
 4) Safety

  • Java provides very good safety feature's like Memory management, Exception handling etc.
  • Servlets inherit all these features & had emerged as a very powerful web server extension.
5) Security

  • Since servlets are server side Components, it inherits the security of server.
  • Servlets are also benefited with java security manager, provided by web server.

Monday, December 12, 2011

What is a Java Servlet ?

Servlet Definition:

Servlet is a small java program that runs on Server-side, which serves as an Intermediate layer between HTTP ( Hyper Text Transfer Protocol) request of a Client and Application's in the Web Server.

A Servlet is a small, pluggable extension to a server that enhances the server's functionality.

Servlets are server side components that provide a powerful mechanism for developing server side programs.

Servlets are both server and platform-independent, so they have no performance limitations.

Servlets run entirely inside Java Virtual Machine at Server.

Servlets have become an alternative to CGI ( Common Gateway Interface ), Due to the performance limitations of CGI programs.

Servlets are used for building Interactive web applications.

Difference Between CGI and java Servlet?

The main difference between the two is that, once Servlet is Initialized it stays in the server container until there are no requests to serve ( ie : it performs multiple requests ). where as, a CGI program gets destroyed once it has fulfilled a request.

Since servlet are initialize once and serve many type, this makes them faster over CGI, Because CGI should always go through the initialize state for every request made.


Browser Compatibility?

Since the Servlet runs at server side , It does not check the Browser for Compatibility.Servlets run entirely inside Java Virtual Machine.

Servlet Classes

Servlets uses the classes in the java packages

  • javax.servlet
  • javax.servlet.http
HTTP Protocols

Servlets are not designed for a specific protocols, but they are often used with the HTTP protocols.

HTTP Servlet are typically used for:
  • Dynamic Content ( like getting the result of a database query and returning to the client).
  • Process or store the data submitted by the HTML.
  • Manage info about an stateless HTTP ( e.g. an online shopping cart manages request for multiple concurrent customers). HTTP as a protocol is stateless.