Servlets

Definition
Servlets are server-side Java programs that handle requests and responses in web applications. Unlike applets, which run in the client’s browser, servlets run on a web server inside a Java container such as Apache Tomcat. They are used to process data, manage sessions, and dynamically generate content for websites and applications.
Servlets form a core part of Java-based web development and provide the foundation for frameworks like JavaServer Pages and Spring MVC.
Advanced
At an advanced level, servlets follow the Java Servlet API, which defines how they receive HTTP requests and return responses. The lifecycle includes initialisation, request handling through the service method, and destruction. Servlets can interact with databases, business logic layers, and other APIs to generate dynamic content.
Advanced setups integrate servlets into enterprise architectures, where they work with filters, listeners, and frameworks to support authentication, routing, and scalability. Performance is enhanced through thread management and connection pooling.
Why it matters
Use cases
Metrics
Issues
Example
An online banking application uses servlets to handle login requests and generate personalised account dashboards. The servlet processes authentication, queries the database, and sends back secure HTML pages to the user.