Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session conflict with servers on the same IP and different ports

 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run servlet on localhost HttpSession.getId() returns id = A

Then I run servlet on localhost:8080 I got a new session B

Then I go back to run servlet on localhost I got a new session C!

Then I go back to run servlet on localhost:8080 I got a new session D!

The sessions seem to step on each other. Why?

 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Bruce.

Have you disabled cookies on the browser side?
 
Kamal Mettananda
Ranch Hand
Posts: 51
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Are you running your web server in two ports (80 and 8080) ? It seems you are calling urls on two ports.

Can you explain the way you are using these two ports?

Cheers,
Kamal
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those are all different domains as far as cookies are concerned. And as cookies goes, so goes the session.
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 1 Tomcat on port 80 and another on port 8080.


if those are all different domains as far as cookies are concerned, why session on domain bumps session on another domain?
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Bruce.
if those are all different domains as far as cookies are concerned, why session on domain bumps session on another domain?


I am guessing, I have not tried this.
Session id's are created randomly. Container creates one 'session id' for one domain and another 'session id' for another domain.
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ssion id's are created randomly. Container creates one 'session id' for one domain and another 'session id' for another domain.

That's what I thought. The confusion thing is that


When I run servlet on localhost I got a session A

Then I run servlet on localhost:8080 I got a new session B

Then I go back to run servlet on localhost I got a new session C! (session A disappeared!)

Then I go back to run servlet on localhost:8080 I got a new session D! session B disappeared!)

Basically when I go to one of the URLs the session Id in another Url is invalidated.

 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Tomcat in both ports 80 and 8080.
I am not sure if this happens in other server too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic