Servlet introduction


Release date:2023-12-12 Update date:2023-12-12 Editor:admin View counts:189

Label:

Servlet introduction

What is Servlet?

Java Servlet is a program that runs on a Web server or application server and acts as an intermediary between a request from a Web browser or other HTTP client and a database or application on the HTTP server.

Use Servlet can collect user input from web page forms, render records from databases or other sources, and create web pages dynamically

Java Servlet can usually achieve the same effect as a program implemented using CGI (Common Gateway Interface, Common Gateway Interface). But comparedwith CGI,Servlet, it has the following advantages:

  • The performance is obviously better.

  • Servlet is executed in the address space of the Web server. This eliminates the need to create a separate process to handle each client request.

  • Servlet are platform independent because they are written in Java.

  • The Java Security Manager on the server enforces a series of restrictions toprotect resources on the server computer. Therefore, Servlet is credible.

  • The full functionality of the Java class library is available to Servlet. Itcan interact with applets, database, or other software through sockets and RMI mechanisms.

Servlet architecture

The following figure shows the location of Servlet in the Web application.

Image0

Servlet task

Servlet performs the following main tasks:

  • Read explicit data sent by the client (browser). This includes HTML forms ona web page, or forms from applet or a custom HTTP client program.

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

  • Process the data and generate the results. This process may require accessing the database, making RMI or CORBA calls, invoking Web services, ordirectly calculating the corresponding response.

  • Send explicit data (that is, documents) to the client (browser). The document can be in a variety of formats, including text files (HTML or XML),binaries (GIF images), Excel, and so on.

  • Send an implicit HTTP response to the client (browser). This includes telling browsers or other clients what type of document is returned (such asHTML), setting cookies and cache parameters, and other similar tasks.

Servlet package

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

Servlet can be used javax.servlet and javax.servlet.http package creation, 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 timeof writing this tutorial, the corresponding versions are Java Servlet 2.5 and JSP 2.1.

Java Servlet, like any other Java class, has been created and compiled. After you install the Servlet packages and add them to the Classpath classpath on your computer, you can compile Servlet through JDK’s Java compiler or any other compiler.

What’s the next step?

Next, this tutorial will take you step by step to set up your Servlet environment so that you can start using Servlet later. So please fasten yourseat belt and start your Servlet learning journey with us. I’m sure you’ll enjoy this tutorial.

Powered by TorCMS (https://github.com/bukun/TorCMS).