Get your CodeRanch badge!*
The moose likes JSP and the fly likes How to access java beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to access java beans" Watch "How to access java beans" New topic
Author

How to access java beans

Kathy OConnell
Greenhorn

Joined: Dec 03, 2001
Posts: 29
I have just started learning JSPs and am running them from Tomcat version 4.
I have copied the examples folder to my own folder (called Kathy) and am trying to run the examples from within my own folder. I have changed the server.xml file to add the Kathy folder to the Context as shown below.
When I run simple JSPs from the Kathy folder, all works fine eg the date program. However when I run a jsp which imports a bean eg numguess, then I get a Tomcat 4.1 500 error.
I am guessing that I am missing some pointer to the folder where the source and class files exist. They are in the C:\jtomcat4\tomcat\webapps\kathy\WEB-INF\classes\num folder. Where do I set up this pointer??
I look forward to hearing from you
<!-- Tomcat Examples Context -->
<Context path="/examples" docBase="examples" debug="0"
reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_examples_log." suffix=".txt"
timestamp="true"/>
<Ejb name="ejb/EmplRecord" type="Entity"
home="com.wombat.empl.EmployeeRecordHome"
remote="com.wombat.empl.EmployeeRecord"/>

<!-- Kathy code Context -->
<Context path="/kathy" docBase="webapps/kathy" debug="0"
reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_examples_log." suffix=".txt"
timestamp="true"/>
<Ejb name="ejb/EmplRecord" type="Entity"
home="com.wombat.empl.EmployeeRecordHome"
remote="com.wombat.empl.EmployeeRecord"/>
</Context>
greg philpott
Ranch Hand

Joined: Nov 10, 2000
Posts: 73
just change the environmental setting CLASSPATH to point to the dir/dir's that have your classes.
If that doesnt work search your tomcat start script to see if that is setting your classpath, and change it there. (should be ${TOMCAT_HOME}/bin/startup .sh or .bat(for windows).
set your classpath like this:
SET CLASSPATH=C:\yourclasses;C:\yourlib\classes.jar;.
or (on unix)
setenv CLASSPATH /yourlib/classes.jar:/yourclasses/:.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

You shouldn't have to play games with the CLASSPATH to make things work, and in fact, I'm not certain that in Tomcat's case that would even help. Tomcat maintains serveral distinct classpaths internally and it's sufficiently complex that I'll simply say if you need to know, check the Tomcat documentation at their website.
You are listing an "Ejb" tag in your server.xml, but your message topic simply says "java beans", so I'm going on the assumption that you either aren't worrying about EJBs (yet) or that you just copied the specimen code. The EJB tag is specific to Tomcat 4 and I don't even know how functional it is at the moment. Also, it's best to know how standard JavaBean classes are located before going to the more complex EJB mechanism.
So, for a NON-EJB named "Walkabout" in source file "Walkabout.java" (note capitalization!), which contains the statement:
package com.wombat.employee;
You'll need to place the compiled class "Walkabout.class" (Again, note capitalization!) in as follows.
For a Windows system, with tomcat4 installed on drive C:
C:\Tomcat4\webapps\kathy\WEB-INF\classes\com\wombat\employee\Walkabout.class
Or in the case of Linux (other Unix-like systems similar) typically:
/var/tomcat4/webapps/kathy/WEB-INF/classes/com/wombat/employee/Walkabout.class
Did I mention that filenames must be precisely capitalized? Windows people often get into trouble because Windows doesn't care but Java does.
Also, I recommend trying out a non-bean JSP (just something like "Hello, World") first, just to make sure that the problem is in fact related to the JavaBean and not to basic operation.


Customer surveys are for companies who didn't pay proper attention to begin with.
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Originally posted by greg philpott:
or (on unix)
setenv CLASSPATH /yourlib/classes.jar:/yourclasses/:.

Or perhaps:
CLASSPATH=/yourlib/classes.jar:/yourclasses/:.
export CLASSPATH
Depends on your shell.
But, as indicated, you should not have to change CLASSPATH for TC.
Incidentally, you can display the JSP classpath with code like the following:
String cPath = (String)context.getAttribute("org.apache.catalina.jsp_classpath");
// path separator is stored by user code
// in the 'contextInitialized' method
// (not shown). 'attrPrefix' is a custom
// prefix known to all my servlets/JSP's
// and it's initialization is also not shown.
String pathSep = (String)context.getAttribute(attrPrefix + "path.separator");
if ( cPath != null )
{
out.println("<h2>JSP CLASSPATH Information</h2>");
out.println("<BLOCKQUOTE><PRE>");
StringTokenizer toker = new StringTokenizer(cPath, pathSep);
for(int i = 1; toker.hasMoreTokens(); ++i)
{
out.println( i + " " + toker.nextToken());
}
out.println("</pre></blockquote>");
}

Regards, Guy
Sam Dalton
Author
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
Check out the presentation that I gave at JavaOne last year on the subject of deploying web application, that ought to point you in the right place. Tim is right in that you DON'T need to modify the classpath, and in fact you should not do this.
The presentation is avaliable on my website at
http://www.samjdalton.com/
Click on conferences, and it is under the JavaOne heading.
S


<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access java beans
 
Similar Threads
DataSource : No suitable driver...?????
question related to servlet class and how to run it from Root
virtual hosting with tomcat
Root Context - mywebapps has no effect
Problem with new contex