• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request.getSession(false) in JSP

 
Gurdershan Singh Bagga
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gurdershan Singh Bagga wrote:.. because I have specified null in the request method,..

How did you achieve this?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
    • 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
    Author and ninkuma
    Marshal
    Pie
    Posts: 64717
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • 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
    • 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,
     
    Chetan Natu
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • 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
    • Quote
    • Report post to moderator
    Thats all I need the directive.

    Thanks all for your help.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic