• 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

Do JSPs always create a session?

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have heard a couple times now that JSPs will always create a session whether you want one or not. Is that true?

http://www.techper.net/2008/07/21/a-jsp-file-always-creates-a-session/
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To be honest I'm not sure, and I haven't checked the spec to see whether any behaviour is mandated.
Certainly a session must be created if you refer to the implicit session object, but whether one is still created if you don't use that object is not clear.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you care?
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I care because I dont want a session created unless I specify that I want one created. I work hard to write sessionless applications because I want every grain of memory available that I can get.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How much memory have you determined that an unused session consumes?
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's probably not that much memory individually, but if my app gets 1,000,000 unique visitors a day, then it all adds up. I'm not out to change the servlet spec, mostly just curious.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On jsp page a session object will be created always. There is no way to stop that. If you use page directive as <@page session="false"> then session will be created but will not be available on jsp page.

You can place a filter in your application and check for session.isNew(). This will show you if the session is created is new one or old one. You can perform your working on based of this check.

May be this will be helpful to you.
 
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vk jain:
On jsp page a session object will be created always. There is no way to stop that. If you use page directive as <@page session="false"> then session will be created but will not be available on jsp page.



I think this must depend on the application server. I have JSPs running on Jetty 6.1 where no session is created if I set <@page session="false">.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A page directive session attribute's default value is true, now.. it means the predefined variable session should be bound to the existing session if one exists, otherwise a new session should be created and bound to it.

I think this must depend on the application server. I have JSPs running on Jetty 6.1 where no session is created if I set <@page session="false">.



I totally disagree with your statement because the session is created no matter whichever application server you use.
with <@page session="false"> you just mean that no sessions will be used, and attempts to access the variable session will result in errors.

You can't do this...

<% if (something) {
session.setAttribute(...); // use session here
} else {
// code that does NOT use session here
}
%>
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to Javaranch Sch�n Sinn ,

I agree with you, behavior of JSP is independent of the application server or the JSP container as long as the server follows the specification
 
reply
    Bookmark Topic Watch Topic
  • New Topic