An introduction to servlet configuration interface

The ServletConfig interface provides a standard abstraction for the servlet object to get environment details from the servlet container. Container implementing the ServletConfig object supports the following operations:
  • Retrieve the initialization parameters from xml file.
  • Retrieve the ServletContext object that describes the application’s runtime environment.
  • Retrieve the servlet name as configured in xml.

HttpServletRequest Interface


The HttpServletRequest interface is a subtype of ServletRequest interface. Implementation for this interface is provided by the servlet container. The HttpServletRequest interface object allows us to access the data available in the HTTP headers and HTTP requests. Following methods helps us to access the header information:
  • String getHeader(String)
  • Enumeration getHeaders(String)
  • Enumeration getHeaderNames()

Following methods helps us to access the path information:
  • String getContextPath()
  • String getServletPath()
  • String getPathInfo()
  • String getRequestURI()

HttpServletResponse Interface


The HttpServletResponse is a subtype of ServletResponse interface. Implementation for this interface is provided by the servlet container. The HttpServletResponse interface object let’s us to specify information that will be a part of the HTTP response headers or the HTTP response. Following methods helps us to manipulate the HTTP response headers:
  • addHeader(String name, String value)
  • containsHeader(String name)
  • setHeader(String name, String value)
  • setDateHeader(String name, long date)
  • addIntHeader(String name, int value)
  • addDateHeader(String name, long date)

Following table shows some of the header fields and the description of their value:
Other methods provided by this interface are:
  • sendError(int)
  • sendError(int, String)
  • sendRedirect(String URL)

After the sendError() method is invoked, we cannot send any response messages to the client.
Take your time to comment on this article.

Comments