• 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

Request.getSession(false) in JSP

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to do like

<%=request.getSession(false) %> in my JSP.

I wonder how I am getting session object all the time I guess It should be null because I have specified FALSE in the request method, but still I always get session object.
So is it like an implicit session object is always created for JSP no matter we use it or not.

Please suggest.
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gurdershan Singh Bagga wrote:.. because I have specified null in the request method,..


How did you achieve this?
 
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
A few things:
  • Why?
  • Scriptlets? In 2010? Really?
  • If you don't want a JSP to particpate in a session, there's a directve for that. (But again, why?)
  •  
    Gurdershan Singh Bagga
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you are stuck in 15 yr old application you do require scriplets..
    Thats the answer for big Why???

    Now again I have corrected the question instead of Null its False actually.
    So, I would really appreciate is someone could explain be this behaviour or let me know how to stop it.

    Thanks again,
     
    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
    The "why" is asking why do you care if there is a session or not? If you don't want to answer, that's up to you.
     
    Gurdershan Singh Bagga
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The reason I care about is because I am using a Sessionlistner in my application and for any exception I am invalidating the session and then redirecting it to the error jsp.
    Now this error.jsp again creates a session object that is caught by sessionCreate event in my listner. On session create event I am assigning some resources to the user so what happens is that when some exception comes I snatch some resources and the same amount of resources are again given to this useless session.

    I had a workaround that checks session.isNew() before assigning resources but I just want to know that can I stop creation of session object when I am redirecting to error.jsp.

    Thanks,
     
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Gurdarshan,

    If you remember, there is a page directive for the JSPs



    amongst other things, if you have not mentioned this attribute for page in the JSP, by default session is activated for the JSPs, so even if you do request.getSession(false) in the code, it won't matter, because session object is already associated with your JSP (implicit object). So if you do not want the session then use the directive listed above.

    If you could explain what kind of resources you are associating with the user, I might be in a better position to discuss a better work-around with you for the problem.
     
    Gurdershan Singh Bagga
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thats all I need the directive.

    Thanks all for your help.
     
    If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic