FYI: be careful how you setAttribute and getAttribute for session requests.
I've read a few resources online that state that using request.getSession().getAttribute("name") is the same as using request.getAttribute("name") and this is not generally true.
My development framework uses the Jetty 5.x embedded Jetty jsp context and web server. The jsp code is sensitive to where in the object hieararchy the "get" is used, so I recommend that any where you use:
request.setAttribute("name")
to get consistent results use
request.getAttribute("name")
to recover the attribute from the session.
Similarly , if you use :
request.getSession().setAttribute("name")
use
request.getSession().getAttribute("name")
to extract the object from the session. I spent a few hours over looking an inconsistency in how I was using the methods before I realized it was the source of an intermittent null pointer exception so keep your sets and gets consistent to avoid weird exceptions!
Regards,
David
[989 byte] By [
sent2nulla] at [2007-11-27 3:54:25]

# 1
>I've read a few resources online that state that using
>request.getSession().getAttribute("name") is the same as using
>request.getAttribute("name") and this is not generally true.
More than that. It is patently wrong.
Request attributes and session attributes are in completely different scopes.
request.getSession().getAttribute is maybe the same as session.getAttribute()
Because the implicit session variable comes from calling request.getSession()
To avoid confusion in my servlets, I normally get the session as a local variable anyway. It is implicit in JSPs, so I use the same name in servlet.
ie
HttpSession session = request.getSession();
session.getAttribute("name");
# 2
> to extract the object from the session. I spent a few
> hours over looking an inconsistency in how I was
> using the methods before I realized it was the source
> of an intermittent null pointer exception so keep
> your sets and gets consistent to avoid weird
> exceptions!
Of course Http Request and Http Session are 2 different objects, with different behavior.
Thanks for sharing.
> Regards,
>
> David
# 4
> This is not new to us :)
>
> I can imagine anyway that it is confusing for unaware
> developers. It's just all about scoping.
>
> Request attributes have a lifetime of one request.
> Session attributes have a lifetime of one session.
I agree... it is far better to remember the concepts than remember the code, because things make better sense that way
> That's all you need to know at least.