• Post Reply Bookmark Topic Watch Topic
  • New Topic

getSession(false)

 
kri shan
Ranch Hand
Posts: 1486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getSession(false).setAttribute("count", new Integer(1));
Is it possible to set the count attibute in the session, because we are passing false to the getSeesion()
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds plausible:
request.getSession(false) // You're using the *current* session, not creating a new one
setAttribute ("current", new Integer(1)); // You should be able to set this attribute just as you would any other

I don't see anything wrong with your approach - it looks OK to me.

'Hope that helps .. PSM
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
passing false to getSession will not return a session if one doesn't exist. If you try and set an object in a non-existent session, you may have a problem.

Are you 100% sure that a session exists for the user?

If your state is managed effectively, this shouldn't be a problem. If it's not, say hello to the world of a NullPointerException. Runtime Exceptions Suck.

Cheers,

-Cameron
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!