File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 agree. Here's the link:
subject: Issue with getSession().setAttribute()
It's not a secret anymore!