Multiple choice technology programming languages

Given the following deployment descriptor: InitParams com.osborne.c02.InitParamsServlet initParm question14 What is the outcome of running the following servlet? (Choose one.) public class InitParamsServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext sc = this.getServletContext(); PrintWriter out = response.getWriter(); out.write("Initialization Parameter is: " + sc.getInitParameter("initParm")); } }

  1. A runtime error

  2. "Initialization Parameter is: null" written to the console

  3. "Initialization Parameter is: question14" returned to the requester

  4. "Initialization Parameter is: null" returned to the requester

  5. "Initialization Parameter is: question14" written to the console

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In the deployment descriptor, initParm is configured as a servlet-specific initialization parameter under `. In the servlet code,sc.getInitParameteris called on theServletContext`, which retrieves context-wide parameters rather than servlet-specific ones. Thus, it returns null, making the output 'Initialization Parameter is: null'.