A Servlet Javadoc!!

The javax.servlet package

javax.servlet.Servlet interface methods

init()
service(ServletRequest req, ServletResponse res)
destroy()
get ServletConfig()
getServletInfo()

javax.servlet.GenericServlet(abstract) implements all methods of Servlet interface except service().

javax.servlet.http.HttpServlet(abstract) overloads
service(ServletRequest, ServletResponse)
with
service(HttpServletRequest,HttpServletResponse)
and in addition defines methods doXXX() for GET, HEAD, POST, DELETE, PUT, OPTIONS, TRACE

The javax.servlet.Servlet interface
All servlets must implement this interface directly or indirectly.
The javax.servlet.GenericServlet class
It is an abstract class that provides implementation for all methods of javax.servlet.Servlet interface except the service() method. This class can be extended and its service method implemented to write any type of servlet.
javax.servlet.ServletRequest interface
This is a generic interface defines methods that can be used to extract information from the Request
javax.servlet.ServletResponse interface
This is a generic interface that defines methods that can be used to generate a http response to the client.
javax.servlet.http package
This package provides support for the http protocol. Classes and interfaces in this package extend the corresponding interfaces and classes in the javax.servlet package.
javax.servlet.http.HttpServlet class
This class extends javax.servlet.GenericServlet and provides a different implementation of the service method:
protected void service(HttpSerlvetRequest req, HttpServletResponse res) throws ServletException,IOException;
In the servlets we write we extend our HttpServlet and override its service() method.
Understanding the sequence of events in HttpServlet
The ServletContainer calls the
service(ServletRequest req. ServletResponse res)
method of theHttpServlet class.
This method calls the
service(HttpservletRequest req, HttpServletResponse res)
method of the same class(HttpServlet) which in turn calls the method doXXX() based on the information obtained from the request object.
Note that the service() method is overloaded in the HttpServlet class.
Overloaded Methods:
service(ServletRequest req. ServletResponse res) throws ServletException, IOException
service(HttpservletRequest req, HttpServletResponse res) throws ServletException, IOException.
If any of these methods are overridden the programmer may have to provide some of the functionality so that the appropriate doXXX() method is called.
All doXXX() methods take two parameters HttpServletRequest and HttpServletResponse.
The HttpServletRequest and HttpServletResponse are interfaces that are implemented by classes providedby the servlet containter.
The servletRequest and HttpServletRequest objects provide methods that help us to analyze the data inthe incoming request(parameters/meta-data/text/binary/).
ServletRequest provides methods to handle requests in any protocol while HttpServletRequest adds HTTP specific methods to handle requests.
Sending the response
The HttpServletResponse provides methods that accepts data that the servlet needs to send to the clientand formats it in a HTTP specific way as per the HTTP specification.

About cuppajavamattiz
Matty Jacob - Avid technical blogger with interests in J2EE, Web Application Servers, Web frameworks, Open source libraries, Relational Databases, Web Services, Source control repositories, ETL, IDE Tools and related technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: