File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Losing session attribute

 
Kedar Dravid
Ranch Hand
Posts: 333
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
James Carman
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic