SERVLET API

SERVLET API :

The javax.servlet and javax.servlet.http packages are the two packages that contain interfaces and classes for building servlets and together constitute Servlet API.
The javax.servlet package contains a number of interfaces and classes used by servlets or container
The javax.servlet.http package contains a number of interfaces and classes that are used to build servlets that work with HTTP requests and responses.

Servlet Interface :
It contains a number of interfaces and classes. The Servlet interface declares methods to initialize , service  and destroy a servlet from the server. These are life-cycle methods of a servlets.

METHODS OF SERVLET INTERFACE :

Methods Use
void init(ServletConfig config) Initializes the servlet. Initialisation Parameters are obtained from ServletConfig,object, sc. It is invoked by the web container only once.
void service(ServletRequest request, ServletResponse response): Provides response for the incoming request. It is invoked for every HTTP request, by the container.
void destroy() Invoked only once , when the servlet is destroyed or unloaded form memory.
ServletConfig getServletConfig() Returns a ServletConfig object which contains any initialization parameters.
String getServletInfo() Returns information about servlet
CREATING SERVLET USING SERVLET INTERFACE :
 
index.html

Preview.java

web.xml

Leave a Reply

Your email address will not be published. Required fields are marked *