This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
the option 2 is correct. The explanation is as follows:
1. It is a JSP file
2. If there is no <%@ page session="false" %> explicitly, then session is set to true by default. It means, that the session object is created before the very first line of the JSP page (in the jsp's servlet class definition).
This question befuddles me too...I tried it out in tomcat and it printed Hello the first time. So, I then printed the session attribute count. So, it prints Hello 1 ! everytime. Does it mean that 1. there already is a session existing since request.getSession(false) doesn't create a session if there isn't one already ? 2. ok, assuming there is a session already, the value of getAttribute would be null becuase otherwise, it would come to the out.println statement. But its going to the setting the attribute else. But aren't we typecasting a null value to an Integer. How is that not throwing an exception ?
Hopefully, I have made my doubts clear...Could someone help us out ? Thanks.