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

Why Session objects are different?

 
walter wang
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
// here is to create a session, if doensot exist
HttpSession hs=request.getSession();
System.out.println("session by getSession():"+ hs);
// here is to get current session,which
// is created at above
System.out.println("session by getSession(false ) :"+request.getSession(false ));
Print out as below ,but why two print out session object are different ?() rg.apache.catalina.session.StandardSessionFacade@23f1bb
session by getSession(false ) rg.apache.catalina.session.StandardSessionFacade
@d33a6b

Edited to remove smilies.
[ April 30, 2002: Message edited by: Mike Curwen ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All that is happening is that you are getting two different instances of the session back, so session1 != session2, but that doesn't mean !session1.equals(session2)
ie they aren't the same instance, but they could still represent the same data.
 
walter wang
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:
All that is happening is that you are getting two different instances of the session back, so session1 != session2, but that doesn't mean !session1.equals(session2)
ie they aren't the same instance, but they could still represent the same data.

I checked, even use session1.equals(session2) returns false, but session1.getId() is same as
session2.getId(), so i guess it still means they represent same session
btw. i used Tomcat
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Walter, I just tested it in websphere and both sessions were the same. The equals method also returned true.
[ May 01, 2002: Message edited by: Bosun Bello ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic