DEV Community

Cover image for Applet, Servlet, and JSP in Java
Harini
Harini

Posted on

Applet, Servlet, and JSP in Java

What is Applet?

An Applet is a small Java program that runs inside a web browser or an applet viewer. It was mainly used to create interactive web applications but is now obsolete because modern browsers no longer support it.

Features

  • Runs on the client side.
  • Extends the Applet class.
  • No main() method.
  • Uses lifecycle methods like init(), start(), stop(), and destroy().

Note: Applets are no longer used in modern Java web development.

What is Servlet?

A Servlet is a server-side Java program that handles client requests and generates dynamic web content. It runs inside a web server such as Apache Tomcat.

Features

  • Runs on the server.
  • Handles HTTP requests and responses.
  • Improves performance by using multithreading.
  • Extends HttpServlet.

Servlet Lifecycle

  1. init() – Initializes the servlet.
  2. service() – Processes client requests.
  3. destroy() – Cleans up resources before removal.

Advantages

  • Fast and efficient.
  • Platform-independent.
  • Secure and scalable.
  • Supports session management.

What is JSP (JavaServer Pages)?

JSP (JavaServer Pages) is a server-side technology used to create dynamic web pages by embedding Java code inside HTML.

Features

  • Simplifies web page development.
  • Automatically converted into a servlet by the server.
  • Supports HTML, CSS, JavaScript, and Java.
  • Ideal for displaying dynamic data.

JSP Lifecycle

  1. Translation into a Servlet.
  2. Compilation.
  3. Initialization (jspInit()).
  4. Request Processing (_jspService()).
  5. Destruction (jspDestroy()).

Advantages

  • Easy to write and maintain.
  • Reduces Java code in web pages.
  • Reusable using JSP tags and Expression Language (EL).
  • Better separation of presentation and business logic.

Top comments (0)