Servlet is Java technology for writing the server side applications. It is the core technology used for developing any Java server applications. Any other Java frameworks created are internally using the servlet for hiding the complex part of how servlet handles the web application request and renders the response. However, knowing the internals of servlet technology is more important to understand the Java web frameworks. This post updated with comprehensive list of servet tutorials for the beginners and advanced developers.
Latest servlets version is 3.1. The following are the key features introduced in the 3.1 release. It is part of Java EE 7 package.
- Non-blocking IO APIs. Servlet 3.0 introduced the Asynchronous IO operations, how ever it doesn’t guarantee the blocking of IO operations which may reduce the performance. 3.1 introduces the event listeners to notify the IO blocking.
- HTTP protocol upgrade mechanism.
- Security enhancements.
Servlet API History
|Servlet API Version
|Java EE / JDK
|Features / Changes
|Non-blocking I/O, HTTP protocol upgrade mechanism
|JavaEE 6, JavaSE 6
|Pluggability, Ease of development, Async Servlet, Security, File Uploading
|JavaEE 5, JavaSE 5
|Requires JavaSE 5, supports annotation
|J2EE 1.4, J2SE 1.3
|web.xml uses XML Schema
|J2EE 1.3, J2SE 1.2
|J2EE 1.2, J2SE 1.2
|Becomes part of J2EE, introduced independent web applications in .war files
|First official specification, added
|Part of Java Servlet Development Kit 2.0
Servlets Basic Tutorials
- Introduction to Servlet : Servlets are an important component of a J2EE application. Servlets along with JavaServer Pages (JSP) and EJB modules can be termed as server-side J2EE component types. Servlet is a Java Programming Language.
- Servlet API : This tutorial lists the important Servlet API and provides the brief description about each API.
- Servlet LifeCycle : Lifecycle of the servlet instance. It explains the init, service and destroy methods with examples.
- Generic Servlet and Http Servlet : Two types of servlet objects and its use.
- Servlet Example : This is the first hello world servlet with easy to understand explanation.
- Web.xml : Deployment descriptor, a core component for web application is explained in this tutorial.
- Servlet Context : How to use the servlet context and initialize it. A nice tutorials with examples.
- Request Dispatcher In Servlet : How to use Request Dispatcher and the important methods in it. Read this post for simple examples about the page navigation using request dispatcher and simple explanation.
- sendRedirect in Servlet : SendRedirect method invokes the new request from the client side instead of doing the redirect from the server side, this has few advantages over the forward method defined in the RequestDispatcher object. Read this article for examples.
- ServletConfig in Servlet : ServletConfig is important for initializing and passing the servlet specific parameters to the class. This values are directly accessed in the init method of the servlet class. Developer can initialize the param in the web.xml.
- Difference Between Servlet and JSP : A decade old debate of JSP and Servlet differences. We again lists the known differences which could be useful for the beginners who are new to these technologies.
- MVC Architecture Using Servlet And JSP : Model – View – Controller (MVC) architecture using the JSP and Servlet technologies. Before the arrival of MVC frameworks, these techniques are widely used for achieving the MVC design.
- SingleThreadModel In Servlet : Currently it is deprecated and not used by the developers, this API useful for enforcing the threads to execute in the single thread. It is very rarely used by any developer since it would impact the performance.
- HTTP Status Codes : Server returns the status codes with the response. These codes indicate the result of the request. There are number of status codes with the different meaning. These are very common across any web applications. This post lists down the status codes with its meaning.
- Difference Between Forward And sendRedirect In Servlet : An important difference and frequently asked interview question, one is redirect at the server side and another one is redirect from the client side. This post explains the difference with simple example.
- ServletInputStream and ServletOutputStream : InputStream and OutputStream for the servlets. It is used for sending the files to the browser and open in the appropriate file types.
- How To Initialize Variables In Servlet : The variables in the servlets are initialized in the init() method of the servlet. These variables can be used in the service() method or doGet() or doPost() methods.
- How To Set PDF File Display In Servlet : This tutorial explains the content type PDF for opening the PDF files in the browser.
- How To Refresh Servlet : Example code for refreshing the server for given intervals.
- Request Headers In Servlet : The details about the request headers sent across every request.
- Session Tracking Using Servlet : How to track session using servlets.
- Servlet Filter : Servlet Filters are one of the important aspect for filtering the request parameters and customize the request. This is very often used in monitoring the request.
- How To Get Client IP Address In Servlet : This post explains the simple example for getting the client IP address using servlet program.
- Cookies In Servlet : One of the session tracking technique is using cookies. Read this tutorial for knowing the example code.
Servlets 3.0 Tutorials
The latest major version of the servlet specification is Servlets 3.0. The following are tutorials related to the latest version.
- Servlet 3.0 Basics : Servlets 3.0 basics and new features.
- Asynchronous Servlets in Servlets 3 : It is one of the key feature with the latest version. Servlets can work Asynchronously without waiting for the response. This will help us to design more advanced web applications using the servlet itself.
- New Features in Servlets 3.0 : List of new features in the servlets 3.0.