Web Applications Development

Saturday, April 6, 2024

Introduction to J2EE

 

 Web Application Model


Servlet

Servlets are Java programs that run on Web or application servers, acting as a middle layer between requests coming from Web browsers or other HTTP clients and databases or applications on the HTTP server


Tasks Performed
  • Read the explicit data sent by the client
  • Read the implicit HTTP request data sent by the browser
  • Generate the results
  • Send the explicit data (i.e., the document) to the client.
  • Send the implicit HTTP response data
Advantages of Servlets
  • Efficient
    • If there are many requests to the same servlet, only a single copy of the servlet class would be loaded
  • Convenient
    • Have utilities like parsing, decoding HTML form data, cookie & session handling, etc.
  • Powerful
    • Servlets can communicate directly to the Web server
    • Multiple servlets can also share data
  • Portable
    • Run on All operating systems and servers
  • Inexpensive
  • Secure
    • Servlets are not executed by general-purpose operating system shells
    • No buffer overflow attacks
What is a container? (Servlet Engine)

Servlets don’t have a main method. Because of that, they are under the control of another java application called container : Tomcat is an example of a container

Servlet Life Cycle



  • init
    • Executed once when the servlet is first loaded or at server start.
    • Performs initializations such as setting up a database connection, loading a data file, etc.
  • service
    • Each time the server receives a request for a servlet, the server spawns a new thread and calls service(). 
    • The service method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc., as appropriate.
  • destroy
    • Called when server deletes servlet instance.
    • It will close database connections, halt background threads, write cookie lists or hit counts to disk, and perform other such cleanup activities

Basic Servlet Structure



Web Application Structure






Next Chapter : Servlet



No comments:

Post a Comment

Popular Posts