The online explanation is as follows:
Class = "package. Class"
Use the New Keyword and the class constructor to sample a bean from a class. this class cannot be abstract and must have a common constructor without parameters. the package name is case sensitive.
Type = "package. Class"
If the bean already exists in the specified range, write the bean to a new database type. If you do not use the class or beanname to specify the type, bean will not be named by the example. Package and class names, case sensitive.
Beanname = "{package. Class | <% = expression %>}" type = "package. Class"
Use the java. Beans. Beans. instantiate method to sample a bean from a class or continuous template, and specify the bean type. Beanname can be package or class, and its value will be passed to beans. instantiate. tupe with the same value as bean.
After the experiment, I understand:
The following two statements have the same meaning:
<%
// Check session to see if there's a cart in it;
Cart cart = (Cart) Session. getattribute ("cart ");
If (Cart = NULL ){
Cart = new cart ();
Session. setattribute ("cart", cart );
}
%>
First:
<JSP: usebean id = "cart" class = "com. Shopping. User. Cart" Scope = "session"> </jsp: usebean>
Second:
<JSP: usebean id = "cart" type = "com. Shopping. User. Cart" Scope = "session"> </jsp: usebean>
Assume that the current cart! = NULL is almost the same as the two. If session is used. setattribute ("cart", null); after setting, the Access contains <JSP: usebean id = "cart" type = "com. shopping. user. cart "Scope =" session "> </jsp: usebean> --- An exception is thrown when the page of the JSP Action Statement (Org. apache. jasper. jasperexception: bean cart not found within scope ). Use <JSP: usebean
Id = "cart" class = "com. shopping. user. cart "Scope =" session "> </jsp: usebean> does not throw an exception. Therefore, the second writing method should have the same meaning as the first writing method. // Why is the same
That is to say, when using class, it first determines whether to get the bean of the instance. If it cannot get the bean, it will use the new keyword to instantiate the bean. When using type, it only finds whether the specified range exists and does not use the class when it does not exist.,Beanname specifies type,This will throw an exception, so pay attention to this when using type.
In addition, the class and beanname must specify the package (even if the package is introduced), and the type can be unspecified.