• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Losing session attribute

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my web application, when I type the URL address as http://localhost:8080/<web-app-name>, I am able to retrieve a session attribute set in a JSP from the same JSP after the request returns to the JSP.
But, if I type the URL as http://<IP Address of machine>/<web-app name>, I am not getting the session attribute value.
This might sound a bit vague. But any suggestions on what might be going wrong are welcome!
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's nothing going wrong.
Browser's bind cookies to the domain from were they come.

When you logged into localhost you started one session.
Then you loggedn with the IP number and your browser started a new one.

The browser has no way of knowing that localhost resolves to that particular IP. As far as it's concerned they are two different sites on two different servers.
 
Kedar Dravid
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me rephrase my question a bit:
I am facing this problem when I shut down Tomcat, and then start the web-app again after typing the IP address into the address bar.
I don't change the URL while the web-app is running!
IOW, in my Web app, if i get the new request using http://localhost previous session is reamining but if I get i get the new request using http://IP addres previous session is destroyin and i am unable to access the attributes stored in session.
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This works for me (as I would expect it should).
The session attributes are maintained irrespective of specifying localhost / IP.

Here's my sample jsp I used to test (on tomcat)



I would suggest you go through your code carefully to see if there's something you have missed.

Cheers,
Ram.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I don't change the URL while the web-app is running!
IOW, in my Web app, if i get the new request using http://localhost previous session is reamining but if I get i get the new request using http://IP addres previous session is destroyin and i am unable to access the attributes stored in session.


It appears to me that you are in fact using two different URLs - one with locahost and one with the IP - I suspect that the browser considers them to be different so it does not transmit the cookie that identifies the session. Exactly what Ben said earlier.

Bill
[ May 06, 2005: Message edited by: William Brogden ]
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you print out the value of the cookie that identifies the session? See if it matches between requests. If it doesn't, then you have your answer.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One tool that I find useful for debugging/researching these types of issues is the LiveHttpHeaders plugin for Mozilla and Firefox.

http://livehttpheaders.mozdev.org/

With it you can see all of the headers, coming from the browser and the server. This includes the JSPSessionID.
 
reply
    Bookmark Topic Watch Topic
  • New Topic