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.
Where did you get that statement? In servlets, sessions are not automatically created, you have to ask for them using HttpServletRequest.getSession. In JSP pages the default is indeed to create sessions, although that can be turned off by a page directive.
(Just to nitpick: it is not the JVM that creates a session, it is the servlet engine)
I'm going to disagree with Ulf, though it may just be a matter of semantics.
Regardless of whether you are using JSPs or servlets, the session itself is created automatically by the servlet container. In a JSP, a reference to the session is automatically created as an implicit variable. In a servlet, you explicitly obtain a reference to the session via the mechanism Ulf describes.
In both cases however, the session itself is automatically created on your behalf.
I created one index.jsp page and then call Servlet. In servlet I am printing all the headers. I am geting session id in that (not used request.getSession()). I have not created that session and session is old.
Shall I consider as you mentioned, container created that session.
Joined: Dec 29, 2005
I think I understand that. When you call your application through index.html and then call Servlet. If you print header, you are not going to get JSessionID.
If you access through index.jsp, because of implicit variable in JSP, you will get that JSessionID.