Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

req.getSession(false)...

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following JSP code (See exhibit).
What will it print for the very first request to this page as well as the web application that contains this page?



Select 1 correct option.
A.It will print Hello!
B.It will print Hello and will set the count attribute in the session.
C.It will throw a NullPointerException at request time.
D.It will not compile.

The answer given is B. I wonder if this is the correct answer because for a very first request req.getSession(false) always returns null.
In the above code else block is executed but it ask for the existing session which is still not available to set the session attribute.

according to me it should print Hello! (option A) please confirm the answer.
 
Janez Novak
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is jsp file, where you have <%@page session="true" %> by default.
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Janez
 
Janez Novak
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic