Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a Question about sessions

 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys, me again !!
I have created a session using
HttpSession session = request.getSession(true).
So far, so good, is working smoothly.
1o.) I'm using a servlet and I need to retrieve some values from the session. I'm doing it this way:
HttpSession session = request.getSession(true)
String someString = session.getAttribute("att")
Am I creating a new session if I do this?? or Am I retrieving the current session (what I actually want to achieve)??
2o.) How do I ask if the session is already created?
using isNew()?
or extracting some value from the session and asking if it is null?
thankssss
 
Mayer Salzer
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) request.getSession(true) retreives the current session if it was already created before otherwise it creates a new one (first time in).
2)There are a number of ways to determine if a session is new. isNew() will work, so will extracting some value from the session and asking if it is null provided you put it into the session before. A third option is checking for request.getSession(false) == null. . .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic