• Post Reply Bookmark Topic Watch Topic
  • New Topic

setMaxInactiveInterval(-1)

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

in above i am using session.setMaxInactiveInterval(-1)?
if i set setMaxInactiveInterval(-1) then isNew() method always return
false.
i know in above code if i will use session.setMaxInactiveInterval(0) it will throws Exception.
That means if we use setMaxInactiveInterval(-1) then session will never created?

Please Help
Thanks
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess a negative number in setMaxInactiveInterval means that session will never expires
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are executing this servlet with any jsp page thats why its session.isNew() return false.If a page is loaded the container will automatically create a session.
So try to run the servlet directly from the browser.
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i check the code. If you run the servlet directly, it will print true.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session.setMaxInactiveInterval(-1) ==> Session never expires.

session.setMaxInactiveInterval(0) ==> is like calling session.invalidate(); session will expire after this statement completes and if you call any method on this session will result in illegalStateException.
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think HFSJ states in its mock exam that, even after an invalidate, we can invoke session.getServletContext() to return the context.
 
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!