Back to Top

Wednesday, 29 February 2012

J2EE: SERVLET: What is Servlet Interface?

Interface javax.servlet.Servlet is that interface which defines the ServletLife Cycle methods. So, all servlets must implement this interface, either directly or by extending a class which implements this interface. Instead of directly implementing the Servlet Interface, a servlet can also extend Class GenericServlet (which implements Servlet Interface), or can extend HttpServlet Class (which extends the GenericServlet class).

Methods of Interface Servlet:
  • init(ServletConfig config) : Called by the Web Container to initialize a servlet. Here, config  is a ServletConfig object containing the servlet's configuration and initialization parameters      
  • service(ServletRequest req, ServletResponse res) : Called by the Web Container to allow a servlet to respond to a request. Here, req is the ServletRequest object that contains the client's request and res is the ServletResponse object that contains the servlet's response.

  • destroy() : Called by the Web Container to clean up a servlet’s service.

  • getServletConfig() : Return a ServletConfig object, which contain the initialization parameter and startup configuration of a servlet.

  • getServletInfo() : Returns a string containing the details of a servlet, like author, version and copyright.
Anijit Sarkar

3 Responses to “ J2EE: SERVLET: What is Servlet Interface? ”

Anonymous said...
26 December 2012 at 10:36

very nice

Pooja Tiwari said...
6 August 2015 at 10:38


Naviya Nair said...
24 October 2016 at 15:00

I have read your blog its very attractive and impressive. I like it your blog.

Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

Online Java Training Java 8 Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes

Java Training Institutes in Chennai Java Training in Chennai

Post a Comment

Popular Posts

All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar
blog links Web Directory Academics Blogs