No, it is not right. Either 'class' or 'type' will do. In this case, when we just have 'type', what will happen is, the jsp container will try to locate an object of 'type' with the 'id' in the given 'scope'. If it is found, then a scripting var is defined with a same name of 'id'. If not found, then an InstantiationException will be thrown. This makes sense because, if we give just a 'type' there can be more than one classes defined in the web app of this 'type'. How can a decision be made which class to instantiate? On the other hand, if we give a 'class' attribute, then the container will attempt to create an object of this class , in case the object is not found in the given scope and given id. For example : <%@ page import='AddressBean' %> <jsp:useBean id='address' type="AddressBean" scope='session'/> For this code in a jsp, the container generated java file will have this code:
From Jsp Spec: Section 4.1 JavaServer Pages 1.2 Specification The actions performed in a jsp:useBean action are: 1. An attempt to locate an object based on the attribute values id and scope. The inspection is done synchronized per scope namespace to avoid non-deterministic behavior. 1. A scripting language variable of the specified type (if given) or class (if type is not given) is defined with the given id in the current lexical scope of the scripting language. 2. If the object is found, the variable�s value is initialized with a reference to the <jsp:useBean> 71 located object, cast to the specified type. If the cast fails, a java.lang.ClassCastException shall occur. This completes the processing of this jsp:useBean action. 3. If the jsp:useBean element had a non-empty body it is ignored. This completes the processing of this jsp:useBean action. 4. If the object is not found in the specified scope and neither class nor beanName are given , a java.lang.InstantiationException shall occur. This completes the processing of this jsp:useBean action.
So the possible right combinations are: 1. class 2. type 3. class and type 4. beanName and type and 'id' is a must attribute. -Maha Anna