• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getSession(false)

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,


Came across this example in one of the mock tests ...





The option given were

1.) Throws NullpointerException
2.) Prints Hello;
3.)None of the above
The Answer is 2.) Prints Hello;


The example said that the page is being accessed for the first time ..

my thought was that request.getSession(false) would be retunning null as the session is not yet created .... is it that since the session attribute of the page directive being default true causes this behaviour.


any explanation to this behaviour ? is it different in JSP and servlet ??
In servlet code i believe request.getSession(false) would have thrown an NullPointerException for the session would not have been created for the first time untill the response is committed.


Thanks,
Reshma
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this thread.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP container provides for each JSP page, implicit variables, you can you in code. One of these variables is session. In order to get session, JSP container calls sesion = request.getSession(), before jsp is started to be executed.

This is fragment of translated jsp page. The attached code is placed before acutal JSP code

try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html;charset=UTF-8");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
.....
 
Reshma Shanbhag
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was a very quick reply ..


Got it now ..


Thanks & Regards,
Reshma
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic