Want to create interactive content? It’s easy in Genially!

Get started free

JAVA EE SLE GROUP 4

067 Arya Sadvilkar

Created on July 11, 2023

Start designing with a free template

Discover more than 1500 professional designs like these:

Higher Education Presentation

Psychedelic Presentation

Vaporwave presentation

Geniaflix Presentation

Vintage Mosaic Presentation

Modern Zen Presentation

Newspaper Presentation

Transcript

TEAM

Exploring Java Servlets and JavaServerPages for Web development SLE Presentation

Arya Sadvilkar - 063 Astha Gorakh - 022 Rinit Jain - 29 Ayyan Pathan - 053

START

Index

04

02

01

03

Life cycle of Servlet

Servlet Interfaces

Servlet API

What is Servlet?

06

07

08

05

Introduction to JSP

Features of JSP

Servet life cycle methods

Stages of life cycle of Servlet

10

11

12

09

JSP Elements

Thanks

Life cycle of JSP

Team

01

What is Servlet?

Servlet is a core aspect of web development in Java. Servlets are the Java platform technology of choice for extending and enhancing Web servers. A Servlet is a class that handles requests, processes them and reply back with a response.

02

Servlet API

The javax.servlet and javax.servlet.http packages represent interfaces and classes for servlet api. The javax.servlet package contains many interfaces and classes that are used by the servlet or web container. The javax.servlet.http package contains interfaces and classes that are responsible for http requests only.

04

Life Cycle of Servlet

Entire life cycle of a Servlet is managed by the Servlet container which uses the javax.servlet. Servlet interface to understand the Servlet object and manage it. So, before creating a Servlet object, let’s first understand the life cycle of the Servlet object.

05

Stages of the Servlet Life Cycle

The Servlet life cycle mainly goes through four stages: 1. Loading a Servlet. 2. Initializing the Servlet. 3. Request handling. 4. Destroying the Servlet. Let’s look at each of these stages in details:

Stages of the Servlet Life Cycle

STAGE 1

STAGE 3

HANDLING REQUEST
LOADING A SERVLET
INITIALIZING A SERVLET
DESTROYING A SERVLET

STAGE 2

STAGE 4

06

Servlet Life Cycle Methods

There are three life cycle methods of a Servlet :

Servlet Life Cycle Methods

Let’s look at each of these methods in details: init() method: The Servlet.init() method is called by the Servlet container to indicate that this Servlet instance is instantiated successfully and is about to put into service.

Servlet Life Cycle Methods

service() method: The service() method of the Servlet is invoked to inform the Servlet about the client requests. This method uses ServletRequest object to collect the data requested by the client. This method uses ServletResponse object to generate the output content.

Servlet Life Cycle Methods

destroy() method: The destroy() method runs only once during the lifetime of a Servlet and signals the end of the Servlet instance.

Example

07

Introduction to JSP

  • It stands for Java Server Pages.
  • It is a server side technology.
  • It is used for creating web application.
  • It is used to create dynamic web content.

JSP pages are more advantageous than Servlet:

  • They are easy to maintain.
  • No recompilation or redeployment is required.
  • JSP has access to entire API of JAVA .
  • JSP are extended version of Servlet.

08

Features of JSP

Make Interactive websites
Coding in JSP is easy
Connection to Database is easier
Reduction in the length of Code
No Redeployment and No Re-Compilation
Portable, Powerful, flexible and easy to maintain

09

JSP Elements

We will learn about the various elements available in JSP with suitable examples. In JSP elements can be divided into 4 different types.

EXPRESSION
SCRIPLETS
DECLARATIONS
DIRECTIVES

JSP Elements

1- Expression: We can use this tag to output any data on the generated page. These data are automatically converted to string and printed on the output stream. Syntax: JSP Expressions are : <%=”Anything” %>

JSP Elements

2 – Scriplets: In this tag we can insert any amount of valid java code and these codes are placed in the _jsp Service method by the JSP engine. Syntax of JSP Scriptles are:

JSP Elements

3- Directives A JSP “directive” starts with <%@ characters. In the directives, we can import packages , and define error-handling pages or the session information of the JSP page. Syntax: JSP directives is:

  • page
  • include
  • taglib

JSP Elements

4 – Declarations This tag is used for defining the functions and variables to be used in the JSP. Syntax: JSP Declaratives are :

10

LIFE CYCLE OF JSP

A Java Server Page life cycle is defined as the process that started with its creation which later translated to a servlet and afterward servlet lifecycle comes into play. This is how the process goes on until its destruction.

LIFE CYCLE OF JSP

Following steps are involved in the JSP life cycle:

  • Translation of JSP page to Servlet
  • Compilation of JSP page(Compilation of JSP into test.java)
  • Classloading (test.java to test.class)
  • Instantiation(Object of the generated Servlet is created)
  • Initialization(jspInit() method is invoked by the container)
  • Request processing(_jspService()is invoked by the container)
  • JSP Cleanup (jspDestroy() method is invoked by the container)

TEAM

Arya Sadvilkar - 063 Astha Gorakh - 022 Ayyan Pathan - 053 Rinit Jain - 029

Thanks!

Initializing a Servlet After the Servlet is instantiated successfully, the Servlet container initializes the instantiated Servlet object. The container initializes the Servlet object by invoking the Servlet.init(ServletConfig) method which accepts ServletConfig object reference as parameter. If the Servlet fails to initialize, then it informs the Servlet container by throwing the ServletException or UnavailableException.

Handling request After initialization, the Servlet instance is ready to serve the client requests. The Servlet container performs the following operations when the Servlet instance is located to service a request : It creates the ServletRequest and ServletResponse objects. After creating the request and response objects it invokes the Servlet.service(ServletRequest, ServletResponse) method by passing the request and response objects. The service() method while processing the request may throw the ServletException or UnavailableException or IOException.

Destroying a Servlet When a Servlet container decides to destroy the Servlet, it performs the following operations It allows all the threads currently running in the service method of the Servlet instance to complete their jobs and get released. After currently running threads have completed their jobs, the Servlet container calls the destroy() method on the Servlet instance.

Loading a Servlet The first stage of the Servlet lifecycle involves loading and initializing the Servlet by the Servlet container. The Servlet container performs two operations in this stage Loading : Loads the Servlet class. Instantiation : Creates an instance of the Servlet. To create a new instance of the Servlet, the container uses the no-argument constructor.