• 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

Session

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey fellas,
I got a Struts web-based application that basically have to provide user's loggon and in each Action I have to check if this "LOGGED" attribute is set. To do this, I put an user object in the session. But I don't know why it do not work:
1) request.getSession().setAttribute("LOGGED", user);
2) String sentinel = request.getSession().getAttribute("LOGGED") == null ? "deny" : "allow";
The issue is that in the second step I allways get null
Is there a "Struts-Way" to manipulate the session scope? Any idea?
Tks,
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
the only possible mistake i can see is that you probably don't have a user-object when storing it to the session in step 1)
just check your 'user'-object or post the entire code of this action.
let me know please
 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Martin,
Thanks for helping me. In fact, I've already checked the user object, and I'm sure that isn't null. Please take a look at the code that matters:

I'm already frustrated with this, hehe. Not even the <bean efine/> tag worked at all, usin' toScope="session" in the login_ok.jsp page (this page manipulate the user object, so I can say that is not null).
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

then in other action classes do this

request.getSession( ) --> will return a session object if it is already there else will CREATE a new one. Now you dont want to CREATE new one in any of your action classes (other than login). So supply a boolean argument false to get to the existing session.(check servlet javadocs).
If the session got expired before reachign this action then you w'd end up creating a new session using this method. try these changes.
 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Karthik, but your changes didn't work for me. Please take a look for the System.out.println:
Existing session org.apache.catalina.session.StandardSessionFacade@c272bc
Why it do not work at all? It's so spooky... Maybe my Tomcat 4.1.24 got some bug. Anybody think so?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic