wood burning stoves 2.0*
The moose likes Servlets and the fly likes Losing session attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Losing session attribute" Watch "Losing session attribute" New topic
Author

Losing session attribute

Kedar Dravid
Ranch Hand

Joined: May 28, 2004
Posts: 333
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Kedar Dravid
Ranch Hand

Joined: May 28, 2004
Posts: 333
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

Joined: Jan 24, 2005
Posts: 489

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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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

Joined: Feb 20, 2001
Posts: 580
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.


James Carman, President<br />Carman Consulting, Inc.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.
 
wood burning stoves
 
subject: Losing session attribute
 
Similar Threads
Running the Application
Need configuration
Security Problem with my app
How do I get my JSP files to run on Eclipse?
integration of struts- jsf Problem related t url