I have Tomcat 3.1 set up on a Windows2000 machine. Let's say I have two jsp pages... file A: "/test.jsp" file B: "/my_folder/test.jsp" ...both "test.jsp", files A and B, are identical. Both files contain: "<jsp:useBean id="me" class="myclass" scope="page" />" the folder "/WEB-INF/classes" contains myclass.class When I try my web browser on file A then everything works fine (thru the web server on localhost, of course). However, I go into file B, then I get this error: <the file's directory> "Class my_folder.myclass not found." so, my question is...how can I get "myclass" to properly work in all directories of the web site? Any help would be greatly appreciated. Thanks in advance. -Ben [ November 23, 2002: Message edited by: Ben Sch ]
How so? I am new to Tomcat administration, so I'm not familiar with a "default package." Would you suggest that I modify some .xml file to make the class visible to all pages?
It's not a Tomcat thing at all, but a Java thing. When you don't use a package declaration in your class it is placed in a "default package". To use an explicit package, place a package declaration at the beginning of your class. For example:
It's a very good idea to place all your classes in a well-orgranized package structure rather than letting them all pile up in the default package. This may solve your problem in that package-less classes seem to confuse some web containers. hth, bear
Thank you for the response, but the problem remains. I have put all my classes into a package. I then tried putting the package into the "/WEB-INF/classes" folder, tried a "/WEB-INF/lib", and even tried "<tomcat dir>/lib/common". None of these made the package visible to the JSPEngine. Since my JSP pages are loading correctly, and the initial javabean class is properly loaded into a page, I suspect that I have tomcat mostly configured. Although, I am still unable to have classes included in pages that are not in the root directy. Do you suppose I need to modify some .xml file or maybe add an environment variable (classpath, etc.) of some sort? [ November 24, 2002: Message edited by: Ben Sch ] [ November 24, 2002: Message edited by: Ben Sch ]
hi ben i think u can add the classpath in one of the configuration files for tomcat i cannot remember the name of the file offhand but if u go thru the conf files u may come across a entry for the classpath for the server. The solution for u'r problem is what Bear had suggested as i too had faced a similar problem in the past. i will try to get my hands on a tomcat server rightaway and get back with the exact file in which the entry needs to be done if u r unable to find it.
There is no need to muck with the Tomcat classpath -- in fact doing so is liable to cause more problems than it would solve. Why not describe how you are setting up your classpath unders WEB-INF classes? If your bean is resident in the correct classpath hierarchy under WEB-INF/classes there is no reason on earth that your JSPs should be unable to see them. No Tomcat configuration mucking about should be required. bear
Please let me know if this information helps figure out the problem. It strikes me that Tomcat knows that there is a web application that I want to run, and that there are some java classes/packages that I wish to use. It just seems that the page that tries to load the
Here is how I'm trying to load it: --------------------------------- <jsp:useBean id="mytable" class="MyTableClass" scope="page" />
Here is a list of my environment variables that relate to Tomcat: ---------------- CATALINA_HOME C:\jakarta-tomcat-3.3.1 CLASSPATH C:\j2sdk1.4.0_02\lib\comm.jar;C:\jakarta-tomcat-3.3.1\bin;C:\jakarta-tomcat-3.3.1\lib\common; C:\jakarta-tomcat-3.3.1\webapps\ROOT\WEB-INF\classes\ JAVA_HOME C:\j2sdk1.4.0_02 PATH C:\j2sdk1.4.0_02\bin;C:\jakarta-tomcat-3.3.1\bin;C:\jakarta-tomcat-3.3.1\webapps; to describe again the funny behavior: ------------------ the page itself could be called xyz.jsp when I try loading the class at /xyz.jsp everything works fine when I try loading the class at /mydir/xyz.jsp I then get the funny error that says "Class mydir.MyTableClass not found." Thanks for any help. -Ben [ November 25, 2002: Message edited by: Ben Sch ] [ November 25, 2002: Message edited by: Ben Sch ]
Rajesh is correct: you must specify the fully-qualified path name of the class. Otherwise, how does Java know where to look for it? Scenario: The bean class named MyBean is defined in package com.bensch.beans. In your java file you will need:
Your java file will be named MyBean.java and will reside in a folder relative to the root of you project as such (assume Windows):
When you compile you will do so from c:\projectroot. In your web app, the class file should end up in
And finally, your useBean directive will contain
Notice how the package hierarchy is carried throughout the process. hth, bear [ November 26, 2002: Message edited by: Bear Bibeault ]