Jay Shukla wrote:
Does it work because of sb is declared at block level and you tried to access unig pageContext because pageContext also covers block scope or
pageContext.getAttribute() will give you attribute at any level.
As per i know pageContext will give you attribute at page level unless you specify scope as a third argument in setAttribute method.
This worked because jsp:useBean works in a way that if attribute is not found in the scope (by default, page) mentioned
then a new object of type is created and set as an attribute in the same scope so translated code is something like this.
Now sb.append("hello") works entire because container exposes this attribute thru the same "id" attribute i.e. sb. If by saying that "sb is declared at block level" you mean that it was used in jsp:useBean inside a block so
container created it, you are right.
However sb is declared inside a block and can't be accessed outside it so <%= sb %> won't work
Kamal Tripathi
SCJP 1.4 90%, SCWCD5 94%, Next SCDJWS--> In Naescent stage. Researching abt exam and material itself.