This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes Request.getSession(false) in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Request.getSession(false) in JSP" Watch "Request.getSession(false) in JSP" New topic
Author

Request.getSession(false) in JSP

Gurdershan Singh Bagga
Greenhorn

Joined: Oct 02, 2008
Posts: 8
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

Joined: Nov 04, 2009
Posts: 2066

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

How did you achieve this?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61314
    
  66

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?)


  • [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Gurdershan Singh Bagga
    Greenhorn

    Joined: Oct 02, 2008
    Posts: 8
    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

    Joined: Jan 10, 2002
    Posts: 61314
        
      66

    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

    Joined: Oct 02, 2008
    Posts: 8
    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

    Joined: Dec 03, 2005
    Posts: 19
    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.


    Never Remember the failure
    Never Forget the mistake
    Gurdershan Singh Bagga
    Greenhorn

    Joined: Oct 02, 2008
    Posts: 8
    Thats all I need the directive.

    Thanks all for your help.
     
    GeeCON Prague 2014
     
    subject: Request.getSession(false) in JSP