aspose file tools*
The moose likes Servlets and the fly likes Why Session objects are different? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why Session objects are different?" Watch "Why Session objects are different?" New topic
Author

Why Session objects are different?

walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 154
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 ]

public class Walter { public boolean is_Working_Now (boolean is_boss_Coming) { return is_boss_Coming; }
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Jun 02, 2001
Posts: 154
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

Joined: Nov 06, 2000
Posts: 1510
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 ]

Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Session objects are different?