This document discusses servlet architecture and how servlets work. It defines servlets as Java programs that extend capabilities of servers to dynamically generate web pages. Servlets allow managing application flow and implementing business logic on the server-side. There are two main types of servlets: generic servlets and HTTP servlets. Servlets follow a request-response workflow, where a client request is sent to the web server and forwarded to a servlet container, which calls service methods to generate a response back to the client. The document outlines key components of servlet architecture like the client, web server, and servlet container.
3. SERVLET ARCHITECTURE
• Servlets are grouped under the Advanced Java tree that are used to create dynamic web
applications. Servlets are robust in nature, well scalable and are primarily used in
developing server-side applications. If we go a little back in time, we would be able to witness
that before the introduction of servlets, CGI (Common Gateway Interface) were used
4. OTHERTASKS THAT A SERVLETCAN DO EFFECTIVELYARE:
• Caneasily manage/controltheapplicationflow.
• Suitabletoimplement business logic.
• Caneffectively balancethe loadattheserver-side.
• Easilygeneratedynamicweb conten
5. TALKING ABOUT THE TYPESOF SERVLETS,THEREARE PRIMARILY
TWO TYPES
• Generic Servlets
• HTTPServlets
6. THERE ARE THREE POTENTIAL WAYS IN WHICH WE CAN EMPLOY TO CREATE
A SERVLET
• Implementing Servlet Interface
• ExtendingGenericServlet
• ExtendingHTTPServlet
7. COMPONENTS OF SERVLET ARCHITECTURE
• Below is thehigh level architecturediagramofservlet. Let’sseein brief, howdoeseachcomponentaddtotheworkingof a
servlet
8.
9. CLIENT
• The client shownin thearchitectureaboveis primarilyworkingasa medium whois sending outHTTPrequestsover tothe
webserver andagainprocessing theresponseit getsbackfromtheserver. As wecansee in thediagram,ourclient hereisthe
web browser.
10. . WEB SERVER
• Staticweb server
• Dynamicwebserver
Primaryjob ofaweb server is toprocessthe requestsandresponsesthata usersendsover time andmaintainhowaweb user wouldbe
able toaccessthefiles thathasbeen hostedover theserver
11. HOW DOES A SERVLET REQUEST FLOW
• Everyservlet shouldoverridethe following3 methodsnamely:
• init()
• service()
• destroy()
12. • Theclient sendsovera request.
• Therequest is acceptedby theweb server andforwarded to theweb container.
•Nowprotectedservice() methodis called bythe publicservice() method.
•Theprotectedservice() methoddispatches therequest to thecorrect handlermethod based onthe typeof request