Hi there�
I have some doubts regarding JSP tag <c:set>. P. 447 of HFSJ book includes the following:
I you do not use the optional �scope� attribute in the tag, and you�re using �var� or �target�, the container will search scopes in the order you�ve come to expect-page � page, then request, then session, then application (context)
If you use �var� version without a scope, and the container can�t find an attribute of that name in any of the four scopes, the container makes a new one in page scope.
Then please explain to me why the following code is not working correctly:
Servlet code
JSP code
The JSP outputs :
Mark
Mark
Rather than
John
John
Why is that? The� name� variable exists in the request forwarded by the servlet. The JSP went on and created a new attribute in page scope and assigned the value �John� to it. In other words, <c:set> tag didn�t search all scopes. Only checked the default scope �page�, and when didn�t find a variable named �name� it automatically created one and refrained from checking other scopes.
A similar scenario applies to <jsp:useBean> tag, when the type attribute is used without �class�, <jsp:useBean> doesn�t search all scopes when the �scope� attribute is not used. Thus choosing the third option as an answer �as the book did� for the exercise in page 356 is incorrect.
Any clarification?
Hatim