
Play Store Application link – Advance java – in 15 steps – Apps on Google Play
Learn with our youtube video –
1- javax.servlet – This package is used for protocol-less requests.
– It contains 14 interfaces and 11 classes. (You don’t need to learn them all though)
2- javax.servlet.http- This package is used for http protocol requests.
– It contains 8 interfaces and 7 classes. (again, you don’t need to learn them all)
Note– (i) javax.servlet package has subpackages, javax.servlet.http is one of them.
tabular comparison of some of the main classes and interfaces in javax.servlet
and javax.servlet.http
:
javax.servlet | javax.servlet.http |
---|---|
Servlet | HttpServlet |
ServletRequest | HttpServletRequest |
ServletResponse | HttpServletResponse |
ServletConfig | HttpServletConfig |
ServletContext | HttpServletContext |
As you can see from the table, the main differences between the two packages are that the classes and interfaces in javax.servlet.http
are specialized for handling HTTP requests and responses, while those in javax.servlet
are more general purpose.
1- Here is a list of some of the main interfaces in the javax.servlet
package:
Servlet
: The main interface that all servlets must implement. This interface defines the methods that are called by the servlet container to initialize, service, and destroy a servlet.ServletConfig
: An interface that provides initialization information for a servlet. A servlet can access this information using the methods of this interface.ServletContext
: An interface that provides access to the information about the servlet’s environment. A servlet can access this information using the methods of this interface.ServletRequest
: An interface that provides information about a client’s request to the servlet. A servlet can access this information using the methods of this interface.ServletResponse
: An interface that provides information that a servlet uses to create a response to a client’s request. A servlet can access this information using the methods of this interface.Filter
: An interface that defines methods that are called by the servlet container to filter requests and responses.FilterChain
: An interface used to invoke the next filter in a chain of filters.ServletRequestWrapper
andServletResponseWrapper
: These interfaces are used to wrap an existing request or response object, so that additional functionality can be added to it.SingleThreadModel
: A marker interface which, when implemented by a Servlet class ensures that only one request at a time is processed.ServletInputStream
andServletOutputStream
: used for reading and writing respectively in a Servlet.
This list is not exhaustive, but it should give you an idea of some of the main interfaces that are provided by the javax.servlet
package.
2- Here is a list of some of the main classes in the javax.servlet
package:
GenericServlet
: A convenience class that implements the Servlet interface, and is designed to be subclassed by developers. This class takes care of some of the low-level details of servlet management, so that you can focus on the business logic of your servlet.ServletException
: A general exception that a servlet can throw when it encounters a problem.UnavailableException
: Thrown when a servlet is temporarily or permanently unavailable.ServletInputStream
andServletOutputStream
: These classes provides a means for reading and writing binary data to a client and a Servlet respectively.RequestDispatcher
: This class allows a servlet to forward a request to another resource (servlet, JSP file, or HTML file) on the server, or to include the output of another resource in the response.ServletRequestAttributeEvent
andServletRequestListener
: these classes and interfaces are used for listening to attribute events on ServletRequest.
This list is not exhaustive, but it should give you an idea of some of the main classes that are provided by the javax.servlet
package. It’s worth noting that the majority of the class in this package are Event Listeners, Filters and Wrappers, which are helper classes used to interact with servlet container.