• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ARRRGGGGHHH - Stupid Javabeans - Again! :(

 
Simon Harvey
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Simon Harvey
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's correct. Then in your JSP, refer to it by its full name -- myPackage.CounterBean.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic