Back to: Java Servlets Tutorials
Java Servlet API with Examples
In this article, I am going to discuss the Java Servlet API with Examples. Please read our previous article where we discussed HTTP Protocols. At the end of this article, you will understand the following pointers in detail.
- Java Servlet API
- Interfaces in javax.servlet package
- Classes in javax.servlet package
- Interfaces in javax.servlet.http package
- Classes in javax.servlet.http package
Java Servlet API
Servlets are created using the javax.servlet and javax.servlet.http packages. These packages are a standard part of Java’s enterprise edition and an expanded version of the Java class library that supports large-scale development projects.
Package javax.servlet.*
It contains a number of classes and interfaces. It describes and defines the contracts between a servlet class and the runtime environment.
Classes in javax.servlet.* package
- AsyncEvent: The event that gets fired when the asynchronous operation initiated on a ServletRequest has completed, timed out, or produced an error.
- GenericServlet: It is used to define a generic, protocol-independent servlet.
- HttpConstraintElement: It is a java class representation of an HttpConstraint annotation value.
- HttpMethodConstraintElement: It is a java class representation of an HttpMethodConstraint annotation value.
- MultipartConfigElement: It is a java class representation of a MultipartConfig annotation value.
- ServletContextAttributeEvent: It is an event class notification about changes to the attribute of the ServletContext of a web application.
- ServletContextEvent: It provides an event class for notifications about changes to the servlet context of a web application.
- ServletInputStream: It provides an input stream for reading binary data from a client request, including an efficient readLine method for reading data one line at a time.
- ServletOutputStream: It provides an output stream for sending binary data to the client.
- ServletRequestAtrributeEvent: An event class for notifications of changes to the attributes of the servlet request in an application.
- ServletRequestEvent: This event indicates lifecycle events for a ServletRequest.
- ServletRequestWrapper: It provides a convenient implementation of the ServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet.
- ServletResponseWrapper: It helps provides a convenient implementation of the ServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet.
- ServletSecurityElement: It is a java class representation of a ServletSecurity annotation value.
Interfaces in javax.servlet.* package
- AsyncContext: The class representing the execution context for an asynchronous operation that was initiated on a ServeltRequest.
- AsyncListener: It is a Listener that will be notified in the event that an asynchronous operation initiated on a ServletRequest to which the listener had been added has completed, timed out, or resulted in an error.
- Filter: It performs filtering tasks on either the request to a resource, or on the response from a resource, or both.
- FilterChain: The servlet container object that provides the developer giving a view into the invocation chain of a filtered request for a resource.
- FiletrConfig: It is a filter configuration object used by a servlet container to pass information to a filter during initialization.
- FilterRegistration: It is an interface through which a Filter may be further configured.
- FilterRegistration.Dynamic: It is an interface through which a Filter registered via one of the addFilter methods on ServletContext may be further configured.
- ReadListener: It gives us a call-back mechanism that will notify implementations as HTTP request data.
- Registration: The interface through which a Servlet or Filter may be further configured.
- Registration.Dynamic: It is an interface through which a Servlet or Filter registered via one of the addServlet or addFilter methods, respectively, on ServletContext may be further configured.
- RequestDispatcher: It defines an object that receives requests from the client and sends them to any resource on the server.
- Servlet: It defines methods that all servlets must implement.
- ServletConfig: It is a servlet configuration object used by a servlet container to pass information to a servlet during initialization.
- ServletContainerInitializer: It notifies of a web application’s startup phase and performs any required programmatic registration of servlets, filters, and listeners.
- ServletContext: It gives a set of methods that a servlet uses to communicate with its servlet container.
- ServletContextAttributeListener: It receives notifications events about ServletContext attribute changes.
- ServletContextListener: It is an interface for receiving notifications events about ServletContext lifecycle changes.
- ServletRegistration: It is an interface through which a Servlet may be further configured.
- ServletRegistration.Dynamic: It is an interface through which a Servlet registered via one of the addServlet methods on ServletContext may be further configured.
- ServletRequest: It defines an object to provide client request information to a servlet.
- ServletRequestAttributeListener: It is an interface for receiving notifications events about ServletRequest attribute changes.
- ServeltRequestListener: It is an interface for receiving notifications events about requests coming into and going out of the scope of a web application.
- ServletResponse: It defines an object to assist a servlet in sending a response to the client.
- SessionCookieConfig: It is a class that may be used to configure various properties of cookies used for session tracking purposes.
- WriteListener: It provides a callback notification mechanism that signals to the developer it’s possible to write content without blocking.
Package javax.servlet.http.*
It contains a number of classes and interfaces. It describes and defines the contracts between a servlet class running under the HTTP protocol and the runtime environment.
Classes in javax.servlet.http.* package
- Cookie: It creates a cookie, a small amount of information sent by a servlet to a Web Browser, saved by the browser, and later sent back to the server.
- HttpServlet: It provides an abstract class to be subclassed to create an HTTP servlet suitable for a Website.
- HttpServletRequestWrapper: It provides a convenient implementation of the HttpServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet.
- HttpServletResponseWrapper: It gives a convenient implementation of the HttpServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet.
- HttpSessionBindingEvent: These events are either sent to an object that implements HttpSessionBuildingListener when it is bound or unbound from a session.
- HttpSessionEvent: It is the class representing event notifications for changes to sessions within a web application.
Interfaces in javax.servlet.http.* package
- HttpServletRequest: It helps us extend the ServletRequest interface to provide request information for HTTP servlets.
- HttpServletResponse: It helps us extend the ServletResponse interface to provide HTTP-specific functionality in sending a response.
- HttpSession: It provides a way to identify a user across more than a one-page request or visit a Website and to store information about that user.
- HttpSessionActivationListener: It is an object that is bound to a session that may listen to container events notifying them that sessions will be passivated and that session will be activated.
- HttpSessionAttributeListener: It gives us notifications of changes to the attribute lists of sessions within the web applications.
- HttpSessionBindingListener: Causes an object to be notified when it is bound or unbound from a session.
- HttpSessionListener: Its implementations are notified of changes to the list of active sessions in a web application.
In the next article, I am going to discuss the Java Servlet Interface in detail. Here, in this article, I try to explain the Java Servlet API with Examples. I hope you enjoy this Java Servlet API with Examples article.