• 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

Servlet Session issues

 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
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
Are both servlets in the same web application? Sessions are only visible inside the web application.
Bill
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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).]
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Joel McNary
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic