English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Servlets provide a component-based, platform-independent method for building web applications without the performance limitations of CGI programs. Servlets can access the entire Java API series, including the JDBC API for accessing enterprise databases. This tutorial will teach you how to develop web applications using Java Servlets through simple steps.
With Servlets, you can collect user input through web forms, display records from databases or other sources, and dynamically create web pages.
Java Servlets typically serve the same purpose as programs implemented using the Common Gateway Interface (CGI). However, Servlets have many advantages over CGI.
Performance is significantly better.
Servlets execute within the address space of the web server. There is no need to create a separate process to handle each client request.
Servlets are platform-independent because they are written in Java.
The Java security manager on the server enforces a set of restrictions to protect the resources on the server computer. Therefore, servlets are trusted.
Servlet can use all the features of the Java class library. It can communicate with applets, databases, or other software through the socket and RMI mechanisms that you have already seen.
Read explicit data sent by the client (browser). This includes HTML forms on web pages, which may also come from applets or custom HTTP client programs.
Read implicit HTTP request data sent by the client (browser). This includes cookies, media types, and compression schemes that the browser can understand.
Process data and generate results. This process may require interaction with a database, executing RMI or CORBA calls, invoking web services, or directly calculating the response.
Send explicit data (i.e., documents) to the client (browser). The document can be sent in various formats, including text (HTML or XML), binary (GIF images), Excel, and so on.
Send an implicit HTTP response to the client (browser). This includes telling the browser or other clients what type of document is being returned (e.g., HTML), setting cookie and cache parameters, and other such tasks.
This tutorial is designed for Java programmers. Before reading this tutorial, you need to understand the Java Servlet framework and its API. After completing this tutorial, you will find that you have reached an intermediate level in using Java Servlets, and you can further improve by self-study and practice.
Before you start reading this tutorial, it is best to have a good understanding of the Java programming language. If you have a basic understanding of web applications and how the internet works, it will help you understand this tutorial.