aspose file tools*
The moose likes Servlets and the fly likes Servlet Session issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Session issues" Watch "Servlet Session issues" New topic
Author

Servlet Session issues

Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

I am trying to store login information in an HttpSession and then check that the user is logged in at the beginning of each servlet in our system. Setting the information seems to work OK; however, when I go to retreive that information I discover that the session does not exist. What am I doing wrong here?
(I'm using Applets that communicate with servlets which in turn communicate with EJBs).
//Set the information in one servlet

//Get the value in another servlet

//And the Reult of the println


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
Are both servlets in the same web application? Sessions are only visible inside the web application.
Bill
tom boshell
Greenhorn

Joined: Jun 26, 2001
Posts: 7
Hello,
Couldn't you just call request.getSession(); in your preCondition method instead of stipulating the value false. That retrieves the session associated with the user. Then if you are worried about it being new use the test session.isNew(), If it is new then that test failed and you can redirect to the login or whatever,
Tom
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821


Originally posted by William Brogden
Are both servlets in the same web application? Sessions are only visible inside the web application.

Yes, both are running in the same web application.

Originally posted by tom boshell
Hello,
Couldn't you just call request.getSession(); in your preCondition method instead of stipulating the value false. That retrieves the session associated with the user. Then if you are worried about it being new use the test session.isNew(), If it is new then that test failed and you can redirect to the login or whatever


This is what I am doing when the user logs in. However, I need not only to know that a valid user is logged in but also who that user is; thus, I don't want to create a new session. I need the old one and the information about who is logged in.
[This message has been edited by Joel McNary (edited September 14, 2001).]
Rama Raghavan
Ranch Hand

Joined: Aug 22, 2001
Posts: 116
Session IDs (if one exist) get passed on each request by the client either via cookies or URL encode.
Are cookies turned off in the browser or your web.xml descriptor ?
_________________________
Rama Raghavan
SCJP2
[This message has been edited by Rama Raghavan (edited September 14, 2001).]


Rama Raghavan<br />SCJP2<br />SCWCD
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

Thank you all for your help, but I managed to identify the issue. For general knowledge, here is what was going on:
The applet would establish a connection to a servlet to pass data back and forth. However, this was a different session from the one that the browser had initiated. Thus, when I set the current employee information in the session of the applet's connection, that information would not be there when the browser went to another page. I worked around this by having the next page the browser go to take userName as a URL parameter and set up the current user there, and then redirect to the appropriate servlet.
Again, that you all for you help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Session issues