Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

FYI: be careful how you setAttribute and getAttribute for session requests.

843838May 9 2007 — edited May 11 2007
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 8 2007
Added on May 9 2007
5 comments
1,224 views