2 Minutes To Code (β Version)

Java Servlets - 2 minute tutorial

Introduction to ServletConfig object

One ServletConfig is created by the web application for each servlet and this object lets the servlet talk to the servlet container.

The servlet parameters that are configured in the deployment descriptor (web.xml) in the <init-param> inside the <servlet> element as shown in the xml below, can be retrieved by the servlet using the methods getInitParameter(String) & getInitParameterNames()of the ServletConfig object.

The ServletConfig object itself can be obtained by the servlets using the method getServletConfig() which they inherit from their superclass GenericServlet.

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException