Servlet Tutorial – Java Servlets Overview

In this servlet tutorial we will see examples of servlet, Java Servlets is a web technology for Java. It was the first web technology for Java and many new web technologies have arrived since. Still, Java Servlets are very useful, both to know, and for certain use cases.

Java Servlets are part of the Java Enterprise Edition (Java EE). You will need to run your Java Servlets inside a Servlet compatible “Servlet Container” (e.g. web server) in order for them to work.

Java Servlets it Java technology for creating the dynamic web applications. Java Servlets are server side components in Java that runs on Servlet enabled web server such as Tomcat, Jetty, WebSphere etc.. Java Servlet is much faster then CGI and Perl since it runs in the same JVM. In case of CGI and Perl separate memory space is allocated for execution of the program which reduces it’s performance.

Servlet technology is robust and scalable as it uses the java language. Before Servlet, CGI (Common Gateway Interface) scripting language was used as a server-side programming language. But there were 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 Tutorial - Java Servlets Overview

Servlets Architecture:

Following diagram shows the position of Servelts in a Web Application.

Java Servlets Overview

Servlets Tasks:

Servlets perform the following major tasks:

Read the explicit data sent by the clients (browsers). This includes an HTML form on a Web page or it could also come from an applet or a custom HTTP client program.

Read the implicit HTTP request data sent by the clients (browsers). This includes cookies, media types and compression schemes the browser understands, and so forth.

Process the data and generate the results. This process may require talking to a database, executing an RMI or CORBA call, invoking a Web service, or computing the response directly.

Send the explicit data (i.e., the document) to the clients (browsers). This document can be sent in a variety of formats, including text (HTML or XML), binary (GIF images), Excel, etc.

Send the implicit HTTP response to the clients (browsers). This includes telling the browsers or other clients what type of document is being returned (e.g., HTML), setting cookies and caching parameters, and other such tasks.

Servlets Packages:

Java Servlets are Java classes run by a web server that has an interpreter that supports the Java Servlet specification.

Servlets can be created using the javax.servlet and javax.servlet.http packages, which are a standard part of the Java’s enterprise edition, an expanded version of the Java class library that supports large-scale development projects.

Servlet Tutorial

Servlet Tutorial Table of Contents

This Servlet Tutorial has a list of the topics covered in this Java Servlet trail. This list (menu) is also present at the top right of every page in the trail.

  1. Java Servlets Overview
  2. Servlets – Environment Setup
  3. Servlet Life Cycle
  4. Servlet API
  5. Servlet Example
  6. What is web application?
  7. Advantages of Servlets over CGI
  8. Servlets – Form Data
  9. GenericServlet
  10. HttpServlet
  11. HttpRequest
  12. HttpResponse
  13. RequestDispatcher
  14. Send Redirect in Servlet
  15. HttpSession
  16. ServletConfig
  17. ServletContext
  18. Cookies Handling
  19. Session Tracking
  20. Servlet Filter
  21. Database Access
  22. File Uploading
  23. Hits Counter
  24. Auto Refresh
  25. Sending Email
  26. Packaging
  27. Debugging
  28. Servlet Internationalization
<<Previous <<   || Index ||   >>Next >>
Next