Hi,
I try to answer your questions.
When you define variable using statement
Here the attribute is set in the page scope. It is very much similar to the follwing statement
No Scripting variables are introduced.
When You use useBaen
<jsp:useBean id="bookId" type="java.lang.String"/>
Though the above bean is not useful, as the
String Object d nat have any useful gettere and setter properties. It is valid. This actin do the following things.
As there is no scope is defined, and no class attribute is present. The action will search the existing page attribute "bookId". It is previously defined in the page scope by the <c:set> JSTL action, so it use the same.
Otherewise if the class attribute of useBean is defined and the attribute "bookId" is not present in the page scope, It will create new String object which value is "" (Empty String).
Also in the present example new scripting variable ise introduce in the current method that is _jspService(..) with the name bookId, which is similar to
<% String bookId = value assigned by bean action %>
So You can use scripting variable like this
<%= bookId %>
The Following Statement
<% cart:remove(bookId); %>
Let us here assume that the tag remove the bookId from the page scope. Note here is that , though the attribute 'bookId" is removed from the scope, the scripting variable bookId still have reference to the object, so you can use this reference in the scripting element.
Another Look at the Example is
You can see the detail codes of these If you view the generated servlet from the JSP.
---------------------------------------------------------------------------
JSTL variable means the attributes in any one of the scope page,request, session,application.
---------------------------------------------------------------------------
<%c

ut value="<%= f>" />
Does not work because there no scriptiong variable f. The JSTL action introduce the attribute named "f" in the loop scope ( I don't know how it is strored) which you can access only in the tag body.
In the last code It is not clear - what is the value of the attribute s1.
Hope this help.
Thanks