Forum Moderators: phranque

Message Too Old, No Replies

Help with invoking a Java Bean from a JSP

usebean class=

         

gbergeron

9:05 pm on Jun 5, 2003 (gmt 0)

10+ Year Member



I have a simple JSP in Tomcat that invokes a javabean:

<jsp:useBean id="converter" class="converters.MyBean" scope="page" >

For some reason, Tomcat cannot find converters.MyBean class

My opening lines of the bean are

package converters;
import java.util.*;
import java.text.*;

public class MyBean {

I have put this everywhere, even declared it in my classpath environment variable.

The JSP (works fine) is defined as a context in the config file. Does my Bean have to be as well?

Alternative Future

9:19 pm on Jun 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi gbergeron,

When the JSP has compiled what is written out for that exact line you have here :
<jsp:useBean id="converter" class="converters.MyBean" scope="page" >

Also if you are sure your configuration files are all correct the only problem I can see is that you have not closed your useBean element off <jsp:useBean id="converter" class="converters.MyBean" scope="page" /> like so! Note: / Also another thing you might want to try is <jsp:useBean id="converter" beanName="MyBean" scope="page" />
beanName - The name of a bean, as you would supply to the instantiate() method in the java.beans.Beans class. This attribute can also be a request time expression.
class - The fully qualified class name.

HTH,

-gs

[edited by: Alternative_Future at 9:45 pm (utc) on June 5, 2003]

txbakers

9:44 pm on Jun 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In your WEB-INF/classes directory of the context, you need to define a sub-directory called "converters" which contains the MyBean.class

The syntax "converters.MyBean" refers to the directory structure. The JSP "package" also refers to the directory. Beans in the same "package" (or directory) can find each other without having further reference.

One other thought - beans need to be in a subdirectory of the WEB-INF/classes path, which you have already by using the converters syntax.

gbergeron

9:53 pm on Jun 5, 2003 (gmt 0)

10+ Year Member



Thanks so much to both AF and TX. Everything works now.
Yes it is crtical to have the classes folder under the WEB-INF. I had mine under a Folder called JSP and it wasn't getting it.

Well done!