Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Servlet Introduction

Servlet Introduction

What is a Servlet?

A Java Servlet is a program that runs on a Web server or application server. It acts as a middle layer between requests from Web browsers or other HTTP clients and databases or applications on the HTTP server.

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

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

Servlet Architecture

The following diagram shows the position of Servlets in a Web application.

Servlet Architecture

Servlet Tasks

Servlets perform the following main tasks:

Servlet Packages

A Java Servlet is a Java class that runs on a web server with an interpreter that supports the Java Servlet specification.

Servlets can be created using the javax.servlet and javax.servlet.http package, which is a standard part of Java Enterprise Edition, an extended version of the Java class library that supports large development projects.

These classes implement the Java Servlet and JSP specifications. At the time of writing this tutorial, the corresponding versions were Java Servlet 2.5 and JSP 2.1.

Java Servlets are created and compiled like any other Java class. After you install the Servlet packages and add them to the Classpath on your computer, you can compile Servlets with the JDK's Java compiler or any other compiler.

What's Next?

Next, this tutorial will guide you step by step through setting up your Servlet environment to begin using Servlets. So fasten your seat belts and join us on this journey of learning Servlets! We believe you will enjoy this tutorial.