Mod 777
Mod 777
PACKAGES
ATIKSH JAIN
1CR22IS026
ABHIMANYU
01
1CR22IS004
JAVA-SERVLET
Introduction
Types of Packages
Introduction
SERVLET LIFECYCLE
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