My knowledge was:
i) request.getSession() or request.getSession(true) returns either the session associated with the request or creates a new session
ii) request.getSession(false) returns either the session associated with the request or NULL if no session exists
Until I came across this in one of the mock tests, which confused me
The question was:
What would happen when the JSP is requested for the first time and this is the first request in the application? I answered that it will throw 'NullPointerException' when trying to perform 'Integer count = (Integer) sessionx.getAttribute("count");', as the session does not exist.
But the correct answer is that it works fine and prints 'Hello!' (also setting the attribute in session).
Also this works as per the answer in
Tomcat.
Anybody can provide an explanation for this?