• Post Reply Bookmark Topic Watch Topic
  • New Topic

Session creation in JSP

 
Anup Om
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

If the home page of my website is a JSP, will the session be created automatically for me (without I using getSession())?

The implicit session object of the JSP is being obtained with a call to the getSession() method of PageContext class. And the API document says, it returns "the HttpSession for this PageContext or null". I don't understand when it returns a null and if it creates a session object when one is not available.

Please let me know the best place to lookup such information? ( I mean like docjar that is used to look at the implementation of Java API classes).

Thanks for your help in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best place to find out how JSPs are supposed to behave is the JSP Specification. Links in JSP FAQ.
 
Poobhathy Kannan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anu

PageContext.getSession() will return the reference to the implicit session object that we define in the page
e.g:

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.

The following will work perfectly


Please correct me if i'm wrong
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except, of course, that scriptlets in JSPs are no longer considered a valid practice.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!