Terms of Service Privacy Policy Contact Us

leistware.com

Servlets

The Servlet Interface...


The javax.servlet.Servlet interface defines methods that all servlets must implement.

  • init(ServletConfig) - called by the servlet container to initialize the servlet.
  • service(ServletRequest, ServletResponse) - called by the servlet container to allow the servlet to respond to a request.
  • destroy() - called by the servlet container for pre-destruction processing.
  • getServletConfig() - returns a ServletConfig object which contains initialization and startup parameters.
  • getServletInfo() - returns information about the servlet.

Two main classes implement this interface.

GenericServlet does not implement the service method of the Servlet interface so that method must be implemented by its decendants.

HTTPServlet implements the service method so it need not be overrode. Therefore, calls to the service method will inturn call the appropriate do method. e.g. an HTTP GET will call doGet, HTTP POST will call doPost. For any do method not specifically overrode in a decendant of HTTPServlet, the service method of HTTPServlet will return an error code 405 (method not allowed or method not implemented).

CREATED 2012-11-04 03:10:38.0

00-17-5D

UPDATED 2012-11-04 03:30:56.0

Request Dispatcher


To methods...

  • getRequestDispatcher(java.lang.String)
  • getNamedDispatcher(java.lang.String)

The difference? Simple: getRequestDispatcher takes a uri... the path to to servlet. getNamedDispatcher takes the name of the servelt as defined in the deployment discriptor file (web.xml).

CREATED 2012-11-05 16:27:24.0

00-17-6B

UPDATED 2012-11-05 16:27:34.0

Knowledge

Servlet Overview
HTTPServlet

Page Server: Ruger

DBID: db.wam

©2012 Leistware Data Systems

      Hello anonymous