Advantages of Servlets
The initialisation code in servlets is executed only once at the beginning of the program and is refreshed automatically on receiving separate requests. Whereas in CGI, separate instances of the program are being invoked each time a process is executed.
The multi threading property of servlets helps in handling separate requests by allocating resource to separate threads. This gives a boost to the performance thereby increasing the efficiency of servlets.
Merits and Demerits of Servlets
Servlets are written using java, which makes extensive use of Java API. The merits of servlets are as described below:
- Enhanced efficiency: Servlet is required to be executed only once at the beginning with the initialisation code. Thereafter it gets auto refreshed each time a request is sent for execution.
- Ease of use: Servlets does not have too many complexities. Its just basic java along with HTML implemented with in java code, which increases the ease of use.
- Powerful: Servlets are java code. Since java is a very powerful language, the usage of java codes makes the servlets a powerful server side scripting language.
- Portable: Java is platform independent and since servlet use java code for writing scripts, it can be executed in any platform.
- Safe and cheap: Usage of java codes provides high security of data to be sent and received thereby maintaining the safety.
The Demerits of Servlet are:
- Low-level HTML documentation: Fragments are written to output stream. Static well-formedness is not maintained, therefore validation is not guaranteed.
- Unclear session management: Flow of control within the codes is very unclear. No enforcement of relation between receiving an output and showing a page.