Stackoverflow

Wednesday, September 29, 2010

Cannot find bean: xxx in scope: xxx

Hi,


Few days back, i came across this error 'Cannot find bean: "myList" in scope: "session" ' while using a struts application. After hours of digging the code, i finally found the cause of the error. It was due to the value "myList" being set null in session.

According to HttpSession API,
If the value passed in is null, this has the same effect as calling removeAttribute()

To avoid the value null being set to the sessionAttributes, use the following snippet.

myList = myLogic.getList();
if(myList==null)
{
session.setAttribute("myList",new ArrayList());
}
else
{
session.setAttribute("myList",myList);
}

No comments:

Post a Comment