On 10/28/15 4:27 AM, Суржин Константин Вадимович wrote:
>> You are asking for a bean with the class name "Animal", and the JSP compiler 
>> and/or runtime >can't find it. I'm guessing you meant to use 
>> "org.animal.Animal" here?
> 
> <jsp:useBean id="animalBean_1" class="org.animal.Animal" scope="session">
> 
> JSP  compiler produce next servlet code:
> org.animal.Animal animalBean_1 = new org.animal.Animal();
> 
> It's OK without  import directive.
> 
> Or 
> 
> <%@page import="org.animal.Animal"%>
> <jsp:useBean id="animalBean_1" type="Animal" beanName="org.animal.Animal" 
> scope="session">
> 
> JSP  compiler produce next servlet code:
> Animal animalBean_1 = (Animal) 
> java.beans.Beans.instantiate(this.getClass().getClassLoader(), 
> "org.animal.Animal");
> 
> And (ClassLoader) the JSP compiler and/or runtime  can find Animal.class
> 
> But:
> <%@page import="org.animal.Animal"%>
> <jsp:useBean id="animalBean_1" class="Animal" scope="session">
> 
> But in this case JSP  compiler produce of different servlet code
> Animal animalBean_1  = (Animal) 
> java.beans.Beans.instantiate(this.getClass().getClassLoader(), "Animal");
> 
> The method instantiate(...,...) does not have a fully qualified name of 
> Animal and It's does not work.
> 
> And (ClassLoader) the JSP compiler and/or runtime TomCat or GlassFish can't 
> find Animal class in /WEB-INF/classes/org/animal/
> 
> So, directive <%@page import="org.animal.Animal"%> has no effect here and 
> beanName="" or class="" org.animal.Animal" cannot be short.
> Only fully qualified class name acceptable.
> Maybe it's a bug.

No, it's not:

http://www.oracle.com/technetwork/java/syntaxref12-149806.pdf

The spec for <jsp:useBean> is that both "type" and "class" attributes
should be specified as "package.Class" and not "Class" with an import. I
think the package name is required, regardless of any page imports.

> But FAQ writes:
> ======================
> Make sure:
> 
> Your bean is packaged in a class.
> You have fully qualified your class name (e.g.: com.bar.package.MyClass ) OR
> You have imported your class into your jsp (e.g.:  <%@ page 
> import="com.bar.package.MyClass"%> )

You don't need to import the class at all if you are always using
<jsp:useBean>.

> =======================
> 
>> Or do you have a class, Animal, in the default package?
> 
> package org.animal;
> public class Animal {...}

Don't use the default package for anything: it's just a recipe for
confusion.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to