Hi,
I found this problem in
java beat's mock exam no.6
--------------------------------------------------------------------------
22. Which statement is TRUE about the following
jsp code snippet?
Please select one correct answer.
<%
String theKey = "key";
String theValue = "value";
session.removeAttribute(theKey); //1
%>
session.setAttribute("<%= theKey %>",
"<%= theValue %>"); //2
session.getAttribute("<%= theKey %>"); //3
<%= session.getAttribute(theKey) %> //4
A. The code compiles but might have runtime NullPointerException at //1
B. There will have compilation error at //2 and //3.
C. There will have output as null at //4.
D. There will have output as theValue at //4
--------------------------------------------------------------------------
Correct answer is C but I think answer B is right.
Reason :- I think answer B is right because at the time of code conversion It will evaluate line no.2 as out.print("session.setAttribute("theKey","theValue");");
Which will result into compilation error...
Can someone please reply whether I am right/wrong?