Multiple choice technology web technology

What is output to the web page on the second access to the same instance of the following JSP? (Choose one.) <%@ page language="java" %> Chapter 6 Question 2

Chapter 6 Question 2

<%! int x = 0; %> <%! public void jspInit() { System.out.println(x++); } %> <%= x++ %> <% System.out.println(x); %> <% jspInit(); %>

  1. 0

  2. 1

  3. 2

  4. 3

  5. 4

  6. Page does not translate.

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

A JSP declaration variable x is static/instance-scoped and persists across requests. Initially, jspInit() is called once during translation/loading (printing/incrementing x to 1). On the first request, &lt;%= x++ %&gt; prints 1 (now x is 2), then prints 3 in the scriptlet. On the second request, &lt;%= x++ %&gt; evaluates to 3 and prints 3.