In the servlet, I am setting an attribute in the request object. In the JSP, trying to create a new attribute in the session scope. And also, trying to print the above attributes in the request and session scope using EL.
SuperCreature is the base class of Person and Dog. And, Person has a Dog.
At step 1, trying to create a new bean in 'session' scope. A bean named 'person' already exists in 'request' scope as set by the servlet.
At step 2, printing the bean using EL that is in the sessionScope and at step3, printing the bean in the requestScope.
At 3, I see the expected result ie. the values set by the servlet. but at 2, I don't see the values set by the Standard action tag <jsp:useBean>. Any ideas?
Using setProperty in the body of useBean does not mean : "set the property of this bean". No, it still means "set the property of the bean defined by "name". Both setProperty and getProperty use pageContext.findAttribute to find the bean they are referring to. So the scopes will be searched in the following order : page, request, session, and application. Your bean in the request will then be found before the bean in the session. [ September 06, 2007: Message edited by: Christophe Verre ]
Note also that getProperty will be called only once : when the bean is created in the session scope. Once the bean has been set in the session, its body will not be executed, so getProperty will not be called.
>>So the scopes will be searched in the following order : page, request, session, and application. So, what is the purpose of 'scope' in the <jsp:useBean ... ?
My understanding from HFSJ is, when the scope is given and if the bean could not be found (provided 'class' is also given) in the given scope, a new bean will be created and set, if <jsp:useBean> has a setproperty in its body.
I rewrote that part as below:
this time, I am setting a new attribute 'person2' (which does not exist in the request or anywhere). This time it worked when I tried to print the attribute from the SESSION as below:
The above code printed the values as 'SAName'. How come?
Meena R. Krishnan
posted 11 years ago
"Note also that getProperty will be called only once : when the bean is created in the session scope. Once the bean has been set in the session, its body will not be executed, so getProperty will not be called."
But, isn't the setProperty also in the body of the action?