Difference between class attributes and beanName for jsp: useBean

What is the difference between the class attribute and the beanName attribute of the jsp:useBean .

+4
source share
1 answer

Just read the <jsp:useBean> documentation (page 35) . Here's an excerpt of relevance:

  • class="package.class" type="package.class"

    Creates a bean instance from a class named class and assigns the bean data type that you specify in type . The value of type can be the same as class , the superclass of class or the interface implemented by class .

    The class you specify in the class must not be abstract and must have an open constructor with no arguments. The names of packages and classes that you use with class and type are case sensitive.

  • beanName="{package.class | <%= expression %>}" type="package.class"

    Creates a bean instance from a class, serialized template, or expression that evaluates to a class or serialized template. When you use beanName , a bean is created by the java.beans.Beans.instantiate method. The Beans.instantiate method checks whether the package and class you specify match the class or serialized template. If they are a serialized template, Beans.instantiate reads the serialized form (which is of type package.class.ser ) using the class loader.

    The type value may be the same as beanName , the superclass of beanName or the interface implemented by beanName . The names of packages and classes that you use with beanName and type are case sensitive.

+12
source

Source: https://habr.com/ru/post/1389049/


All Articles