- 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.