This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to access java beans

 
Kathy OConnell
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic