• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Where does this package go?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm doing an excersize from the 'MySQL and JSP Web Applications' by James Turner. I can't get it to work.

here's the first line of the jsp
<jsp:useBean id="handoff" scope="session" class="com.CARTAPP.user.User" />
I also have a "User" class.
package com.CARTAPP.user;
public class User{
protected String lastName;
protected String firstName;

public String getLastName(){
return lastName;
}

public String getFirstName(){
return firstName;
}

public void setLastName(String lname){
lastName=lname;
}

public void setFirstName(String fname){
firstName=fname;
}

public boolean isValidUserData(){
return ((firstName != null) && (firstName.length() > 0) &&
(lastName != null) && (lastName.length() > 0));
}
}
When I try to run the jsp, I get errors saying the class can't be found. I'm using Tomcat. I'm putting the jsp in c:\cartapp\jsp
I'm putting the User class (already compiled) in c:\cartapp\user.
Where am I supposed to put the class???
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You haven't created the directories according to your Package name ( or you should compile your .java files using the -d option ).
Hope you configured your Web Application's classpath to c:\cartapp\user\
Then you need to create the following Directory structure
com\CARTAPP\user\
inside the c:\cartapp\user\ directory and place the .class files inside the below mentioned directory
c:\cartapp\user\com\CARTAPP\user\
Hope this will help..
-Sateesh
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I appreciate the feedback Sateesh, but I don't think that's it.
I tried your suggestion, however, and it didn't work.
I don't think the "com." in the class section of the jsp is literally looking for a directory "com." I may be wrong, though. The book doesn't really explain much (big surprise).
Any other suggestions???
 
Sateesh Kumar K
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can you post the Error You are getting..
Hope you have modified the Server.xml file which resides in conf directory and there should be an entry for your Web Application
<Context path="c:/cartapp" docBase="cartapp" debug="0"
reloadable="true">
If this is the case then ,
look for the directory structure
c:/cartapp/Web-Inf/classes/
( If not there then create the above structure)
Then place the .class files in the path
c:/cartapp/Web-Inf/classes/com/CARTAPP/user/
-Sateesh
 
chris gar
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are the errors from my browser:Apache Tomcat/4.0.5 - HTTP Status 500 - Internal Server Error
--------------------------------------------------------------------------------
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 1 in the jsp file: /jsp/handoff1.jsp
Generated servlet error:
C:\jakarta-tomcat-4.0.5\work\Standalone\localhost\cartapp\jsp\handoff1$jsp.java:56: Class com.cartapp.user.User not found.
com.cartapp.user.User handoff = null;
^

An error occurred at line: 1 in the jsp file: /jsp/handoff1.jsp
Generated servlet error:
C:\jakarta-tomcat-4.0.5\work\Standalone\localhost\cartapp\jsp\handoff1$jsp.java:59: Class com.cartapp.user.User not found.
handoff= (com.cartapp.user.User)
^

An error occurred at line: 1 in the jsp file: /jsp/handoff1.jsp
Generated servlet error:
C:\jakarta-tomcat-4.0.5\work\Standalone\localhost\cartapp\jsp\handoff1$jsp.java:64: Class com.cartapp.user.User not found.
handoff = (com.cartapp.user.User) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "com.cartapp.user.User");
^
3 errors
---------------------------------
Basically, it can't find the "User" class.
The deployment descriptor is working (other jsp's are running fine from this same directory.)
I'm running this on Tomcat - it isn't deployed on the web.- FYI.
My jsp file resides in c:\cartapp\jsp
I put the user class in several places - basically every possible location (in the c:/com/cartapp/user, also in the c:/cartapp/user/com/cartap/user - also in c:cartapp/jsp/com.... and in c:/cartapp/user/com...
I also checked the Server.xml file and it is set-up properly. I also added the Web-Inf directory per you suggestion and added the User class. Still get the same error.
I must be missing something. Any work-around would be find. I don't care where the bean resides. I'm just in the learning phase.
Thanks again for your help..
Here is the code:
handoff
-----
<jsp:useBean id="handoff" scope="session" class="com.cartapp.user.User" />
<HTML>
<BODY>
This is the setting page!
<%
handoff.setFirstName("George");
%>
</BODY>
</HTML>
here is the user bean class
---------
package com.cartapp.user;
public class User{
protected String lastName;
protected String firstName;

public String getLastName(){
return lastName;
}

public String getFirstName(){
return firstName;
}

public void setLastName(String lname){
lastName=lname;
}

public void setFirstName(String fname){
firstName=fname;
}

}

Again, I really appreciate your efforts.
Best regards
[ October 06, 2002: Message edited by: chris ]
[ October 06, 2002: Message edited by: chris ]
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There seems to be a capitalization discrepancy between the class you posted (com.CARTAPP...) and the generated code that isn't compiling (com.cartapp...)
Are you sure you are being consistent with this?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your bean class is in the com.cartapp.user package, as indicated by:

Then the compiled class file should be placed according to the servlet and JSP rules - ie under the WEB-INF/classes directory for your web application using the package name. As suggested above, the capitalization of directory names, etc must match the actual package, furthermore all upper case WEB-INF is required.
Take a look at the JSP examples provided with Tomcat - they show how the support classes should be placed.
The servlet and JSP API can be downloaded from java.sun.com - anybody trying to work with JSP and/or servlets should have a copy on hand.
Bill
 
chris gar
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your input Chris. I have corrected the CARTAPP/cartapp problem. it should be lower case.
Bill, thanks for your input. I know your suggestion has me going in the right direction (like I need to tell you that.)
Per your suggestion:
I've looked for the JSP examples and where they put their helper classes. I see what you are talking about. WEB-INF, etc. This rings a bell.
The path I'm following:
jakarta-4.0.5/webapps/ then there are several options:
-examples
-manager
-ROOT
-tomcat-docs
-webdav

Since the examples work, and since this directory also has the WEB-INF/classes dir, I tried it first. No dice.
to review, the path for the helper class (in this attempt) :
C:\jakarta-tomcat-4.0.5\webapps\examples\WEB-INF\classes\com\cartapp\user
I still get the same -"can't find User class" error.
For kicks, I also copied the classes folder into the ROOT/WEB-INF dir. Still the same error.
C:\jakarta-tomcat-4.0.5\webapps\ROOT\WEB-INF\classes\com\cartapp\user
Then I did the same for webdav directory. same result.
???
Do I have to restart the server everytime?
Is the "com" a literal? In other words, is this some example abbreviation that really means something else? I'm not seeing any other "com"'s out there. Can I make this easier by eliminating the package statement in the class?
I'm still not getting it. Thanks again for your help and patience.
[ October 07, 2002: Message edited by: chris ]
[ October 07, 2002: Message edited by: chris ]
 
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Goofus McDoofus",
Thanks for participating here at the Ranch. However, the name you are using does not comply with our naming convention described at http://www.javaranch.com/name.jsp . Please log in with a new name, which meets these requirements.
You can change your name here.
Thanks.
Sean
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by chris:
Since the examples work, and since this directory also has the WEB-INF/classes dir, I tried it first. No dice.
to review, the path for the helper class (in this attempt) :
C:\jakarta-tomcat-4.0.5\webapps\examples\WEB-INF\classes\com\cartapp\user
I still get the same -"can't find User class" error.
For kicks, I also copied the classes folder into the ROOT/WEB-INF dir. Still the same error.
C:\jakarta-tomcat-4.0.5\webapps\ROOT\WEB-INF\classes\com\cartapp\user
Then I did the same for webdav directory. same result.
???


Chris,
From what you describe above, it sounds like you're trying to call your User class from a JSP in c:\cartapp\jsp. Note that what Bill says is "the compiled class file should be placed according to the servlet and JSP rules - ie under the WEB-INF/classes directory for your web application using the package name". Neither examples, ROOT, nor webdav are your webapp - apparently, your webapp is c:\cartapp. The class has to go with the webapp that's going to use it. Unless you've moved it, your directory structure should look like c:\cartapp\WEB-INF\classes\com\cartapp\user .

Originally posted by chris:

Is the "com" a literal?


"com" is part of the package name you've chosen. Because it's in your Java code when you specify the package, it has to be in your directory structure. Your class would work just fine if you removed "com" from the package and didn't have a "com" directory. From what I understand, it's somewhat standard to name your packages your domain name, reversed. Hence, a lot of packages start with "com".
g.
[ October 07, 2002: Message edited by: Garann Rose Means ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is the "com" a literal? In other words, is this some example abbreviation that really means something else? I'm not seeing any other "com"'s out there. Can I make this easier by eliminating the package statement in the class?
I'm still not getting it. Thanks again for your help and patience.


Do NOT remove the package statement. All servlet related classes should be in a package. (Although you may see some examples that are not.) The reason being that trying to locate a class not in a package involves looking in the JVM's "current" directory. You have no control over what the JVM thinks is the current directory.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you!
Thank you!
Thank you!
Garann Rose Means & Bill (and others);
I got it! - It's all so simple in hindsight!!!
c:\cartapp\WEB-INF\classes\com\cartapp\user - that's what I needed!

Figuring this out was my primary goal today. You helped acheive it by 7:45 a.m.
In September of last year, I began my quest to learn Java. I had no OO experience. I had only programmed a little in RPG (an older language developed around 1974 -which is basically based on punch card logic). With hard work, and a lot of help from the ranchers at this site, I passed my SCJP2 exam this past June and I'm well on my way to learning the J2EE and getting a better job because of it.
I'm amazed at how great (and patient) the people are who visit this site. Thank you!
Best Regards,
Chris Garrison
[ October 08, 2002: Message edited by: Chris Garrison11 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic