• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JSP can't find bean classes

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm running Tomcat 3.2.3 on Windows 2000. I've been working with servlets and JSP and so far everything has been working fine.
I've just started using JavaBeans in my JSP pages, but whenever I run them I get an internal servlet error with the message: Can't find class xxxbean.
Here is my classpath and directory information:
CLASSPATH:
.;
%JAVA_HOME%\lib\tools.jar;
%TOMCAT_HOME%\lib\jasper.jar;
%TOMCAT_HOME%\lib\servlet.jar;
%TOMCAT_HOME%\webapps\ROOT\WEB-INF\classes;
%TOMCAT_HOME%/webapps/jspwork;
JSP files directory:
C:\java\jakarta-tomcat-3.2.3\webapps\jsp
Bean object:
C:\java\jakarta-tomcat-3.2.3\webapps\ROOT\WEB-INF\classes\beans\StringBean.class

In my JSP file I am using the line:
<jsp:useBean id="stringBean" class="beans.StringBean" />
But it claims not to be able to load the class StringBean.
Any help appreciated.
Richard
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you must import the the bean(the folder where you put your beans). put this code:
<%@page import="beans.*" %>
hth
raymond
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your jsp and the bean class have to be under the same webapp.
It looks like your jsp is under a jsp webapp and your bean is under the ROOT webapp.
|
|-webapps
| |
| |-jspwork
| | (Here be your JSP files)
| |
| |-WEB-INF
| |
| | |-classes
| | |
| | |-beans
| | | (here be your classes)
------------------
I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A. Make sure your java classes are coderanch. <-- obvious, yes, but it's one of those mistakes that will drive you to sell your computer.
B. Use packages. In the first line of code in your classes add 'package myPackage;'. Then put all your beans in on directory. In your useBean tag, use 'class="myPackage.yourClass"',
C. Make sure your CLASSPATH is set properly. Your CLASSPATH is similar to PATH, but it points to the directory of your .class files.
After you do this, and you consider the other replies, you should be good to go.
Stone Golem
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is ROOT in the directory path of ur bean??
the path for jsp file should be
webapps\ur_webapp\jsp\...
for beans it should be
webapps\ur_webapp\WEB-INF\classes\....
------------------
What if this is as good as it gets ?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to use static methods from a class that isn't in a package?
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The containers' classloaders have problems with packageless classes. Best to put your classes in a package regardless of whether you will be accessing them through static references or not.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic