Earlier Common Gateway Interface (CGI) server-side scripts used to generate dynamic content.
Disadvantages of CGI
- Platform dependence
- Lack of scalability
- Always a new process should be created to serve a request. i.e. f there are N simultaneous requests to the same CGI program, the code for the CGI program is loaded into memory N times.
- Not secure
- Expensive, to support this need to purchase proprietary package.
Applets created, but focused on client side only to create web applications, Java Servlets will overcome all these limitations and resides on server side to generate dynamic web page.
What is Servlet ?
Java Servlets are part of the Java Enterprise Edition, is a web component deployed on the server side and is used to create Web Application.
Servlets handles multiple simultaneous requests by creating multiple threads. Will see the same with this simple diagram
Advantages of Servlets
- Portable: Servlets are written in Java, so platform independent
- Works on any OS
- Better Performance: Multi threaded and efficient
- Web servers support. Sun Micro systems supplied the Servlet API to all the vendors to develop Web servers that execute Servlets.
- Inter Servlet communication.
- Secure as they are executed within JVM.
- Powerful, Inexpensive, Convenient to use as it has inbuilt support for HTTP headers, cookies management, session management, Exception handling, Garbage collection etc
- Supports almost all frameworks like Struts, Spring etc.