Showing posts with label Jsp. Show all posts
Showing posts with label Jsp. Show all posts

Tuesday, July 6, 2010

PageContext.getSession() returns null

javax.servlet.jsp.PageContext.getSession() will return the reference to the implicit session object that we define in the page
e.g:
<%... page session="false" %>
<html>
<%= pageContext.getSession() %>
</html>
This will return you a null as we defined ‘false’ for implicit session object.

And I think that PageContext.getSession() would only return the session object if it has been already created otherwise you will get a null.

I mean the bellow one might also get a null unless a session has been already created.
<%... page session="true" %>
<html>
<%= pageContext.getSession() %>
</html>
The following will work perfectly
<%... page session="true" %>
<html>
<% request.getSession(); %>
<%= pageContext.getSession() %>
</html>