Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

how to useBean for all directories?  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try placing your class in a package other than the default package (which is a good suggestion in any case).
hth,
bear
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In e-mail the original author asked:


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
 
Ben Sch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 687
Hibernate jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ben Sch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Specify bean class by giving package hiearchy like-
<jsp:usebean id="objBean" class="package.BeanClass" scope="anyOneOfFour" />
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!