English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Servlet-Übersicht

What is Servlet?

Java Servlets are programs running on Web servers or application servers and act as an intermediary layer between requests from Web browsers or other HTTP clients and databases or applications on the HTTP server.

With Servlets, you can collect user input from web forms, present records from databases or other sources, and also dynamically create web pages.

Java Servlets can usually achieve the same effect as programs implemented using CGI (Common Gateway Interface, public gateway interface). However, compared to CGI, Servlets have the following advantages:

  • Performance is significantly better.

  • Servlets execute within the address space of the Web server. This means that it is not necessary 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 executes a series of restrictions to protect the resources on the server computer. Therefore, Servlets are trusted.

  • All the functionalities of the Java class library are available to Servlets. It can interact with applets, databases, or other software through sockets and RMI mechanisms.

Servlet architecture

The following diagram shows the position of Servlet in the Web application.

Servlet tasks

Servlet performs the following main tasks:

  • Read explicit data sent by the client (browser). This includes HTML forms on web pages, or it can also be forms from applets or custom HTTP client programs.

  • Read implicit HTTP request data sent by the client (browser). This includes cookies, media types, and compression formats that the browser can understand, etc.

  • Process data and generate results. This process may require accessing a database, executing RMI or CORBA calls, invoking web services, or directly calculating the corresponding response.

  • Send explicit data (i.e., documents) to the client (browser). The format of the document can be various, including text files (HTML or XML), binary files (GIF images), Excel, and so on.

  • eine implizite HTTP-Antwort an den Client (Browser) senden. Dies umfasst die Angabe des Dokumententyps, der dem Browser oder anderen Clients zurückgegeben wird (z.B. HTML), das Setzen von Cookies und Cache-Parametern sowie andere ähnliche Aufgaben.

Servlet-Pakete

Java Servlet sind Java-Klassen, die auf Webservern mit einem Interpreter laufen, der die Java Servlet-Spezifikation unterstützt.

Servlet können javax.servlet und javax.servlet.http Paket erstellen, das ein Bestandteil der Java Enterprise Edition ist, die eine erweiterte Version der Java-Klassenbibliothek für große Entwicklungsprojekte ist.

Diese Klassen implementieren die Java Servlet- und JSP-Spezifikationen. Beim Schreiben dieses Tutorials waren die entsprechenden Versionen Java Servlet 2.5 und JSP 2.1.

Java Servlets sind wie jede andere Java-Klasse erstellt und kompiliert worden. Nachdem Sie das Servlet-Paket installiert haben und es in den Classpath Ihrer Computer hinzugefügt haben, können Sie Servlets mit dem Java-Compiler von JDK oder jedem anderen Compiler kompilieren.

Was als Nächstes?

In diesem Tutorial wird Ihnen Schritt für Schritt gezeigt, wie Sie Ihre Servlet-Umgebung einrichten, um mit der Verwendung von Servlets fortzufahren. Daher sollten Sie Ihre Sicherheitsgurte festschnallen und mit uns auf die Reise in die Welt der Servlets aufbrechen! Wir sind sicher, dass Sie diese Anleitung mögen werden.