Saturday, May 2, 2015

Servlet Interface


The javax.servlet.Servlet is the base interface of life cycle methods of servlet. All the servlet classes are required to implement this interface. The methods declared in this interface are:

• public abstract void init(ServletConfig paramServletConfig) throws ServletException
is the very important method that is invoked by servlet container to initialized the servlet and
ServletConfig parameters. The servlet is not ready to process client request until the method is finished executing. This method is called only once in servlet lifecycle and make
Servlet class different from normal java objects. We can extend this method in our servlet classes
to initialize resources such as DB Connection, Socket connections


• public abstract ServletConfig getServletConfig() which contains any initialization parameters and startup configuration for this servlet. We can use this method to get the init parameters of servlet
through annotation in Servlet 3. We will look into ServletConfig interface later on.

• public abstract void service(ServletRequest req, ServletResponse res) throws
ServletException, IOException is the base interface of Servlet API. There are some other interfaces and classes that we should be aware of when working with Servlets. Also with Servlet 3.0 specs, servlet API introduced use of annotations rather than having all the servlet configuration in deployment descriptor. In this section, we will look into important Servlet API interfaces, classes and annotations that we will use further in developing our application.

• public abstract String getServletInfo() – This method returns string containing information
about the servlet, such as its author, version, and copyright. The string returned should be plain
text and can’t have markups.
• public abstract void destroy() – This method can be called only once in servlet life cycle and
used to close any open resources. This is like finalize method of a java class.


No comments:

Post a Comment

Contact Form

Name

Email *

Message *