Servlet API specification provides all the interfaces and classes to be used by the developer to create servlet programs and by container to provide run time environment to execute that servlet. Servlet is the specifications that define and describes the systematic and semantic approach to develop servlet class, which can be developed by the developer, which can be instantiated and executed by runtime environment by providing required implementation.
Servlet API describes and defines the contracts between a servlet class and the runtime environment.
The word framework is used many times which specifies that servlet api is the set of predefined interfaces and classes having some special methods where you will put your codes to execute within that method. Servlet class is instantiated and run by container, it does nothing itself.
This API defines the contracts between a servlet class and the runtime environment provided for an instance of such a class by a conforming servlet container.
There are two packages contain all the required interface and classes necessary to build servlet program.
1.2 javax.servlet
The javax.servlet package contains all classes and interfaces those all used to build servlet having no dependency on networking protocol.
1.2.1 Interfaces
Table 1
1. Filter | It is used to perform filtering tasks on either the request to a resource or on the response from a resource, or both. |
2. FilterChain | The object of FilterChain is provided by the servlet container that provides next invocation chain of a filtered request for a resource. |
3. FilterConfig | It is used by a servlet container to pass information to a filter during initialization. |
4. RequestDispatcher | Implementation’s object of this interface sends requests to any resource (such as a servlet, HTML file, or JSP file) on the server. |
5. Servlet | Defines methods that all servlets must implement. |
6. ServletConfig | It is used by a servlet container to pass information to a servlet during initialization. |
7. ServletContext | The implemented object of ServletContext interface is used by the container to share some common elements within a web application, for all servlet and all client. |
8. ServletContextAttributeListener | Implementations this interface is used to observe the events of ServletContext when some attributes are added or removed. |
9. ServletContextListener | Implementations this interface is used to observe the events of ServletContext when it is created, destroyed etc. |
10. ServletRequest | Container implements this interface to create the request object to provide client request information to a servlet. |
11. ServletRequestAttributeListener | A ServletRequestAttributeListener can be implemented by the developer to listen events on ServletRequest object while adding and removing attributes. |
12. ServletRequestListener | A ServletRequestListener can be implemented by the developer to listen events occur when requests come in and out of scope in a web component. |
13. ServletResponse | Container implements this interface to create the request object to assist a servlet in sending a response to the client. |
14. SingleThreadModel | Deprecated. As of Java Servlet API 2.4, with no direct replacement. |
1.2.2 Classes
Table 2
1- GenericServlet | Implementers Servlet interface and used to create protocol-independent servlet. |
2- ServletContextAttributeEvent | Used by container to create an object created when ServletContext’s attributes are changed, for notifications about changes to the attributes of the servlet context of a web application. |
3- ServletContextEvent | Used by container to create an object when Servlet Context of a web application is changed. |
4- ServletInputStream | Use for reading binary data from a client request, including an efficient readLine method for reading data one line at a time. |
5- ServletOutputStream | Used for sending binary data to the client. |
6- ServletRequestAttributeEvent | Object of this class is created when attributes from the request object are added or removed or changed. |
7- ServletRequestEvent | This is event object created when to notification about request lifecycle. |
8- ServletRequestWrapper | This is concrete implementation of ServletRequest interface that is used to create ServletRequest object manually |
9- ServletResponseWrapper | This is concrete implementation of ServletResponse interface that is used to create ServletResponse object manually |
1.3 javax.servlet.http
This package contains all classes and interfaces to create the servlet program that follow http protocol rules and architecture.
1.3.1 Interfaces
Table 3
HttpServletRequest | This interface Extends the ServletRequest interface to provide request information for HTTP specific servlets. |
HttpServletResponse | This interface Extends the ServletResponse interface to provide HTTP-specific functionality in sending a response. |
HttpSession | Object of HttpSession implementation provides mechanisms to trace the user across multiple requests. And provides the convenient way to store the information of user. |
HttpSessionActivationListener | This is the object that is notified by the container when sessions is activated and that session is passivated (deactivated). |
HttpSessionAttributeListener | This interface is used to build session attribute listener. Object of that class will be notified when attributes of session will be changed. |
HttpSessionBindingListener | Causes an object to be notified when it is bound to or unbound from a session. |
HttpSessionContext | Deprecated. As of Java(tm) Servlet API 2.1 for security reasons, with no replacement. |
HttpSessionListener | Implementations of this interface are notified of changes to the list of active sessions in a web application. |
1.3.2 Classes
Table 4
Cookie | Object of Cookie class represents 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 | This is abstract class having super class as GenericServlet class that is subclassed by developer to create java servlet program. |
HttpServletRequestWrapper | Provides an implementation of the HttpServletRequest interface that can be subclassed by developers to create HttpServ;etRequest Object that can be passed to doGet/doPost method. |
HttpServletResponseWrapper | Provides an implementation of the HttpServletResponse interface that can be subclassed by developers to create HttpServ;etResponse Object that can be passed to doGet/doPost method. |
HttpSessionBindingEvent | Instance of HttpSessionBindingEvent is used to notify the event related to session binding. |
HttpSessionEvent | Instance of This class representing event notifications for changes to sessions within a web application. |
HttpUtils | Deprecated. As of Java(tm) Servlet API 2.3. These methods were only useful with the default encoding and have been moved to the request interfaces. |
Comments