What will be the outcome of a user accessing the following uncompiled
JSP for the first time in a fresh browser session?
Note that the line numbers are for reference, as if the code appeared in a text editor.
[CODE:XML NUM]
<HTML><HEAD></HEAD><BODY>
<P>Session ID: <%-- <%= session.getId() %> --%></P>
<%@ page session = "false" %>
<%
HttpSession session = request.getSession(false);
boolean b = (session == null) ? true : false;
%>
<%= "There is no session: " + b %>
</BODY></HTML>
[/CODE:XML]
Possible Answer(s)
1) A runtime error will occur, caused by a NullPointerException
2) A compilation error will occur because of the misplaced page directive at line 12, which should come before any JSP scriptlets or expressions.
3) A compilation error will occur because the variable "session" will be declared twice - once as an implicit JSP variable, and again at line 14.
4) Ouput will be obtained similar to the following:
Session ID:
There is no session: false
5) Ouput will be obtained similar to the following:
Session ID:
There is no session: true
6) Ouput will be obtained similar to the following:
Session ID: 00JPQXYABCD1234888894RTV
There is no session: false
Correct Answers
Ouput will be obtained similar to the following:
Session ID:
There is no session: true