What is Servlet in Java?

Java servlet is a key component of server-side Java development. A servlet is a small, pluggable extension to a server that enhances the server's functionality.
A servlet is a server-side Java class that can be loaded dynamically to expand the functionality of a server.
  • Servlet is commonly used with a web server.
  • It is used to create a dynamic web page.
  • It is used to developing a dynamic web application.
What is servlet in java
Servlet Architecture
while servlet can be used to extend web servers, providing a powerful, efficient replacement for the CGI script. To understand the power of Servlets, we need to step back and look at some of the other approaches that can be used to create web applications.


Common Gateway Interface:

The Common Gateway Interface, normally referred to as CGI, was one of the first practical technique for creating dynamic content. With CGI, a web server passes a certain request to an external program. The output of this program is then sent to the client in place of a static file.

CGI is not a programming language. It is an interface that allows input from a web browser(client) and produces an output in the form of an HTML page. A CGI script can be written in a variety of language such as c,c++, PERL, FORTRAN, Visual Basic, and even java out of these PERL was most commonly used.


Advantages of CGI:

1) CGI script works with any web browser as well as with most web server running on Windows and Unix.

2) It is a language independent. It can be written in a variety of languages
(c,c++,Perl etc), so the developers don't have to learn a new language.


Disadvantages of CGI:

1) When a server receives a request that accesses a CGI program, It must create a new process to run the CGI program and then pass to it. Creating a process for each such request requires time and significant server resources, which limits the numbers of request a server can handle concurrently.
What is servlet in java
CGI
2) Even though a CGI program can be written in almost any language, the Perl programming language has become the predominant choice. writing a CGI script in Perl gives it a semblance of platform independence, but it also requires that each request start a separate Perl interpreter, which takes even more time and requires extra resources.

3) Another problem with CGI is that a CGI program cannot interact with the web server, because it is running in a separate process.


Advantages of Servlet:

1) Servlets are written in Java, they are highly portable across operating system and across server implementation.

2) Servlets are also well suited for enabling client/server communications.

3) Servlets are platform-independent, the web application developed with servlet can be run on any web container such as Tomcat, Glassfish, JBoss server, etc.

4) Servlets provide better performance in terms of processing time, memory utilization because Servlets uses the benefits of multithreading and for each request, a new thread is created.
What is servlet in java
Servlet
5) Servlets invocation is highly efficient. Once a servlet is loaded, it remains in the server's memory as a single object instance

6) Servlets are managed by JVM so no need to worry about memory leakage, garbage collection, etc.

7) Servlets are secure because it uses java language

8) Servlets are protocol-independent they use any protocol like(FTP, HTTPS, NNTP, etc)


You may also like:

JDBC Driver in Java

What is Servlet in Java? What is Servlet in Java? Reviewed by Prashant Srivastava on September 22, 2018 Rating: 5

No comments:

Powered by Blogger.