0% found this document useful (0 votes)
8 views11 pages

Mod 777

Uploaded by

vabb22ise
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

Mod 777

Uploaded by

vabb22ise
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

JAVA-SERVLET

PACKAGES
ATIKSH JAIN
1CR22IS026

ABHIMANYU
01
1CR22IS004
JAVA-SERVLET

Introduction

Servlet API Overview

CONTENTS Servlet Lifecycle

Types of Packages

Interfaces and Classes


02
JAVA-SERVLET

Introduction

Technology which is used to create a web application


Servlets are web components that run on a Java-enabled web server
or application server
Used to handle the request obtained from the web server, process the
request, produce the response, and then send a response back to the
web server
To create a servlet, you need to implement the Servlet interface or
extend a class that implements it, such as GenericServlet or
HttpServlet
03
JAVA-SERVLET

SERVLET API OVERVIEW


To create Java Servlets, we need to use Servlet API which contains all the necessary interfaces
and classes
provides a standardized way to extend web servers to handle client requests and generate
dynamic responses
Servlet API has 2 packages namely,
javax.servlet
javax.servlet.http
javax.servlet
provides the number of interfaces and classes to support Generic servlet which is protocol
independent
javax.servlet.http
provides the number of interfaces and classes to support HTTP servlet which is HTTP protocol
dependent.
describes and defines the contracts between a servlet class running under HTTP protocol and
the runtime environment provided by a servlet container. 05
04
JAVA-SERVLET

SERVLET LIFECYCLE

managed by the Servlet container which uses the javax.servlet.Servlet interface


servlet has a lifecycle that defines how it is loaded, initialized, invoked, and
destroyed by the web container
This interface defines methods to initialize a servlet, to service requests, and to
remove a servlet from the server. These are known as life-cycle methods and are
called in the following sequence:
init(): The servlet is constructed(loaded), then initialized with the init method
service(): Any calls from clients to the service method are handled(Request
handling)
destroy(): The servlet is taken out of service, then destroyed with the destroy
method, then garbage collected and finalized
06
JAVA-SERVLET

07
JAVA-SERVLET
TYPES OF PACKAGES
In Java servlets, packages are used to organize classes into namespaces, making it easier to manage and maintain code. Here are some
common types of packages used in Java servlets:

**javax.servlet**: This package contains core classes and interfaces for servlets, including HttpServlet, ServletRequest, ServletResponse, and
others. It forms the basis of servlet programming in Java.

2. **javax.servlet.http**: This package extends the javax.servlet package to provide classes specific to HTTP servlets. Key classes include
HttpServletRequest, HttpServletResponse, and HttpServlet.

3. **javax.servlet.annotation**: This package provides annotations used for servlets, such as @WebServlet, @WebFilter, and @WebListener.
Annotations simplify configuration and deployment of servlet components.

4. **javax.servlet.descriptor**: This package includes classes for programmatic access to deployment descriptor information, such as
ServletContext initialization parameters.

5. **javax.servlet.jsp**: Although primarily for JavaServer Pages (JSP), this package includes classes and interfaces that can be useful in
conjunction with servlets, such as JspWriter.

6. **javax.servlet.resources**: This package contains classes and interfaces for localizing messages from the servlet container.

These packages are essential for developing robust servlet applications in Java, providing the necessary classes, interfaces, and 08
annotations to handle HTTP requests, responses, and manage servlet lifecycles effectively.
JAVA-SERVLET
INTERFACES AND CLASSES
Interfaces in javax.servlet package:
1. Servlet: Represents a servlet component that receives and responds to requests
from clients. Classes implementing this interface must override methods such as
init, service, and destroy.
2. ServletRequest: Represents client request information for a servlet. Methods
provide access to parameters, headers, and other request details.
3. ServletResponse: Represents the response a servlet sends to the client. Methods
allow setting response headers, content type, and writing output to the client.
4. ServletContext: Represents the web application's context within the servlet
container. It allows servlets to interact with the container, access initialization
parameters, and manage attributes that can be shared among servlets.
5. RequestDispatcher: Interface used to forward a request from one servlet to
09
another resource (servlet, JSP, or HTML file) on the server-side.
JAVA-SERVLET Interfaces and Classes in javax.servlet.http
packages
HttpServlet: Abstract subclass of GenericServlet that provides HTTP-specific
methods such as doGet, doPost, doPut, doDelete for handling HTTP requests.
Servlets typically extend this class to handle HTTP requests.
HttpServletRequest: Extends ServletRequest to provide additional methods
specific to HTTP requests, such as retrieving request parameters, headers, and
session information.
HttpServletResponse: Extends ServletResponse to provide additional methods
for setting HTTP-specific response headers and status codes, and writing
response content.
HttpSession: Represents a user session in a web application. Provides methods
to store and retrieve session attributes, invalidate sessions, and manage
session timeouts.
Cookie: Represents an HTTP cookie, which is used to store user-specific 10

information on the client-side. Cookies are often used for session


management and personalization
Thank
You
10

You might also like