wood burning stoves
The moose likes JSP and the fly likes Issue with getSession().setAttribute() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Issue with getSession().setAttribute()" Watch "Issue with getSession().setAttribute()" New topic

Issue with getSession().setAttribute()

Tiago Fernandez
Ranch Hand

Joined: May 16, 2003
Posts: 167
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...

Tiago Fernandez
ib idris

Joined: Aug 02, 2003
Posts: 29
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().

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Issue with getSession().setAttribute()
jQuery in Action, 3rd edition