🎴 Flashcard Mode

Java Servlets and JSP Fundamentals

Card1 / 16
Mastered0
Review0
QuestionClick to flip

What will be the output of the following JSP code snippet at run-time when it is accessed the third time? <% int test = 0; %> <% ++test; %> The value of test is <%= test %>

AnswerClick to flip back
A
The value of the 'test' variable will be 1.
💡 Explanation:

The JSP scriptlet <% int test = 0; %> declares a local variable inside the service method. Every time the page is requested, the variable is re-initialized to 0 and incremented to 1, so it always prints 1.

Change Mode