Categories: Servlet

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.

Servlets Architecture:

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

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 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
Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

2 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

2 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

2 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

2 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

2 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

3 years ago