trainingtrains Logo

91-9990449935

 0120-4256464

Servlet Tutorial

java servlet tutorial

Servlet technology is used to create web application (resides at server side and generates dynamic web page).

Servlet technology is robust and scalable because of java language. Before Servlet, CGI (Common Gateway Interface) scripting language was popular as a server-side programming language. But there was many disadvantages of this technology. We have discussed these disadvantages below.

There are many interfaces and classes in the servlet API such as Servlet, GenericServlet, HttpServlet, ServletRequest, ServletResponse etc.

What is a Servlet?

Servlet can be described in many ways, depending on the context.

  • Servlet is a technology i.e. used to create web application.
  • Servlet is an API that provides many interfaces and classes including documentations.
  • Servlet is an interface that must be implemented for creating any servlet.
  • Servlet is a class that extend the capabilities of the servers and respond to the incoming request. It can respond to any type of requests.
  • Servlet is a web component that is deployed on the server to create dynamic web page.
servlet

Do You Know?
  • What is the web application and what is the difference between Get and Post request ?
  • What information is received by the web server if we request for a servlet ?
  • How to run servlet in Eclipse, MyEclipse and Netbeans IDE ?
  • What are the ways for servlet collaboration and what is the difference between RequestDispatcher and sendRedirect() method ?
  • What is the difference between ServletConfig and ServletContext interface?
  • How many ways we can maintain state of an user ? Which approach is mostly used in web development ?
  • How to count total number of visitors and total response time for a request using Filter ?
  • How to run servlet with annotation ?
  • How to create registration form using Servlet and Oracle database ?
  • How can we upload and download file from the server ?

What is web application?

A web application is an application accessible from the web. A web application is composed of web components like Servlet, JSP, Filter etc. and other components such as HTML. The web components typically execute in Web Server and respond to HTTP request.


CGI(Commmon Gateway Interface)

CGI technology enables the web server to call an external program and pass HTTP request information to the external program to process the request. For each request, it starts a new process.

problem in cgi and how servlet is better

Disadvantages of CGI

There are many problems in CGI technology:

  1. If number of clients increases, it takes more time for sending response.
  2. For each request, it starts a process and Web server is limited to start processes.
  3. It uses platform dependent language e.g. C, C++, perl.

Advantage of Servlet

advantage of servlet

There are many advantages of servlet over CGI. The web container creates threads for handling the multiple requests to the servlet. Threads have a lot of benefits over the Processes such as they share a common memory area, lightweight, cost of communication between the threads are low. The basic benefits of servlet are as follows:

  1. better performance: because it creates a thread for each request not process.
  2. Portability: because it uses java language.
  3. Robust: Servlets are managed by JVM so we don't need to worry about memory leak, garbage collection etc.
  4. Secure: because it uses java language..