Servlet uses classes and interfaces from two packages: javax.servlet and javax.servlet.http.They constitute servlet API. Keep in mind that these packages are not part of the Core java packages. Instead, they are a standard extension. Therefore, they are not included in the Java software development kit. you must download tomcat to obtain their functionality.
Every Servlets must implement the javax.servlet.Servlet interface. Most servlet implements this interface by extending one of two special classes javax.servlet.GenericServlet or javax.servlet.http.HttpServlet.
A GenericServlet class provides the implementation of the basic life cycle method of the servlet. The service() method of GenericServlet class accepts two parameters: a request object and a response object. The request object is used to read the data from a client request and the response object is used to write data to a client request.
In contrast, an HTTP servlet usually does not override the service() method. Instead, it overrides the doGet() method to handle the GET request and the doPost() method to handle the post requests. An HTTP servlet can override either or both of these methods, depending on the type of requests it needs to handle. An HTTP servlet can override doPut() and delete() methods to handle PUT and DELETE requests respectively. However,HTTP servlet generally don’t touch doTrace() or doOption().
- java.servlet Package
- Interfaces in javax.servlet package
- Classes in javax.servlet package
- Interfaces in javax.servlet.http package
- Classes in javax.servlet.http package
java.Servlet Package has several interfaces and classes that provide the framework in which servlet operates. Classes and interfaces within the package are protocol-independent.
The ServletRequest and ServletResponse classes in javax.servlet is used to read the data from a client request and write the data to client response, While HttpServletRequest and HttpServletResponse in javax.Servlet.http package also contains an HttpSession class that provides built-in session tracking functionality and a cookie class that allows you to quickly set up and process HTTP cookies.
There are various interfaces in javax.servlet package and they are listed in the following fashion
Also, Refer: What is Servlet in Java?
There are many classes in javax.servlet package and they are listed as follows
- unavailabale Exception
There are several interfaces in javax.servelt.http package and they are in the below fashion
There are many classes in javax.servlet.http package and they are in the following way.
- HttpServletRequestWrapper HttpServletResponseWrapper