2 Minutes To Code (β Version)

Java Servlets - 2 minute tutorial

Introduction to ServletContext object

One ServletContext is created by the web application for all servlets and this object lets the servlets talk to the servlet container.

The web app parameters that are configured in the deployment descriptor (web.xml) in the <context-para,> elements as shown in the xml below, can be retrieved by the servlet using the methods getInitParameter(String) & getInitParameterNames() of the ServletContext object.

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



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