What Is a Java Servlet in a Nutshell? JDBC

In a nutshell, a servlet is a web component that generates dynamic content. Servlets are small, platform-independent Java classes compiled to an architecture-neutral bytecode that can be loaded dynamically into and run by a servlet container or an application server. Servlets interact with web clients (i.e., web browsers) via a request-response paradigm implemented by the servlet container. This request-response model is based on the behavior of HTTP.

The Java servlet’s request-response paradigm

Java servlet’s request-response paradigm

What is a Java servlet? A servlet is an extension to a web server and is used for generating dynamic web content. A servlet gets an HTTP request from a client, such as a web browser; processes the request; and returns the HTTP response to the client. The response typically contains HTML code, XML, or an image (binary data) that is displayed by the web browser. A Java servlet enables dynamic web content from a static web page. Much in the same way other existing scripting languages like CGI or ASP can generate dynamic content based on input given to it by a user, so too does a Java servlet. The advantage of a Java servlet over these other existing scripting languages is its portability. Java was specifically designed so that an application could be written once and run on any operating systems with a virtual machine. Java servlets take this concept further by extending it into the field of server-side scripting.

Servlets are small Java classes that run in a server application (hence the name “servlets,” similar to “applets” on the client side) to answer client requests. Servlets are not tied to a specific client-server protocol, but they are most commonly used with HTTP and the word “servlet” is often used in the meaning of “HTTP servlet.”

Servlets make use of the Java classes in these packages:

  • javax.servlet: The basic Servlet framework
  • javax.servlet.http: Extensions of the servlet framework for servlets that answer HTTP requests

    Typical uses for HTTP servlets include

  • Processing and/or storing data submitted by an HTML form
  • Providing dynamic content, for example, returning the results of a database query to the client (as HTML, XML)
  • Managing state information on top of the stateless HTTP, for example, for an online shopping cart system that manages shopping carts for many concurrent customers and maps every request to the right customer

A Java servlet engine is the Java application that executes the Java servlet. It is a mechanism by which a Java application can be written to provide dynamic web content.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JDBC Topics