aspose file tools*
The moose likes JSP and the fly likes ARRRGGGGHHH - Stupid Javabeans - Again! :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "ARRRGGGGHHH - Stupid Javabeans - Again! :(" Watch "ARRRGGGGHHH - Stupid Javabeans - Again! :(" New topic
Author

ARRRGGGGHHH - Stupid Javabeans - Again! :(

Simon Harvey
Ranch Hand

Joined: Jan 26, 2003
Posts: 79
Hi there everyone,
I am still having a problem with using a simple javabean in my jsp page. I'll put the error message at the bottom of this post. Its essentially saying that the class for the mean can't be found. Here's some additional info that I am desperately hoping will help:
The bean is located in the WEB-INF/classes directory and as such has no package name (i think thats right)
I try and import the bean using:
<jsp:useBean id="counter" class="CounterBean"/>
Now, I use netbeans to compile the javabean and I have a slight feeling that it may be screwing something up. I have already asked roughly this question a good few days ago, and someone said that the compiler is thinking that my classes directory is part of the package. I don't know why he thinks that, but does anyone else concur or have any suggestions.
This is so sill. I just want to do something incredibly basic!
Thanks to anyone who can offer some assistance
Kind Regards
Simon
Amol Desai
Ranch Hand

Joined: Jan 29, 2003
Posts: 82
Hi,
I guess you need to have your CounterBean class in a package.
The class attribute in your <jsp:usebean> should be of the form:
<jsp:useBean id="beanInstanceName" class="package.class" .../>
-Amol
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12786
    
    5
Amol is exactly right. If you don't put ALL classes used in servlets in a package you get hard-to-understand exceptions like that. It has to do with the way classes are located if they don't live in a package.
Furthermore you will want to include an import attribute in a page directive or use the complete package.class name in your code.
Bill
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
You can't import a packageless class (such as your JavaBean) into a packaged class (such as your JSP). I learned this the hard way...


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Simon Harvey
Ranch Hand

Joined: Jan 26, 2003
Posts: 79
Thanks everyone,
I'm a bit dubious though because the reason I put the bean in a packageless class is to make it as simple as possible - it wasn't working when I did have it in a package either.
Just so I know what I'm doing, do I put a folder in ...\classes
eg
\classes\my_package
and then in the javabean, my code will have
package my_package
at the very top. I'll give that a try in a second. I really hope this works!
Thanks again everyone. Thats a big help
Simon
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
That's correct. Then in your JSP, refer to it by its full name -- myPackage.CounterBean.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ARRRGGGGHHH - Stupid Javabeans - Again! :(