This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with getSession().setAttribute()

 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What's wrong with the followin' code?

1) Settin' the session attribute:
request.getSession().setAttribute("logged", user);

2) Checkin' if the user is logged:
String status = request.getSession().getAttribute("logged") == null ? "deny" : "allow";
if (status.equals("deny"))
// do something here...

The problem is that getAttribute() always returns null...
Tks,
 
ib idris
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JSP you don't have to use request.getSession() but session. If you always get attribute null, maybe user is always null or the session is invalidated at some point. You can check with session.isNew().

http://galileo.spaceports.com/~ibidris/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic