If you don’t specify a scope in either the <jsp:useBean> or <jsp:getProperty> tags, the Container uses the default of “page”.
This
<jsp:useBean id="person" class="foo.Employee" scope="page"/>
Is the same as this
<jsp:useBean id="person" class="foo.Employee"/>
Don’t confuse type with class!
Check out this code:
<jsp:useBean id="person" type="foo.Employee" class="foo.Person"/>
Be prepared to recognize that this will NEVER work! You’ll get a big fat:
org.apache.jasper.JasperException: Unable to compile class for JSP foo.Person is abstract; cannot be instantiated Person = new foo.Person();
Be SURE that you remember:
type == reference type class == object type
Or to put it another way:
type is what you DECLARE (can be abstract) class is what you INSTANTIATE (must be concrete) type x = new class()
Now, you’re probably thinking, “Well DUH—class is always a class while type doesn’t have to be—type can be an interface. So of COURSE they used “class” to represent things that must ALWAYS be a class, and “type” for things that can be interfaces as well.” And you’d be right. But you’re also thinking, “Of course, not EVERYTHING in the spec has the most intuitive and obvious name, so I better be sure.” Sometimes (like security <auth-constraint>), the name of a thing is the opposite of what it actually is. But in this case, class is class, and type is... type.
BE the Container
<jsp:useBean id="person" type="foo.Employee" scope="request" >
<jsp:setProperty name="person" property="name" value="Fred" />
</jsp:useBean >
Name is: <jsp:getProperty name="person" property="name" />
Now imagine that a servlet does some work and then forwards the request to the JSP that has the code above. Figure out what the JSP code above would do for each of the two different servlet code examples. (The answers are at the end of the chapter.)