Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't locate class - first program attempt  RSS feed

 
Jean Jenkins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm new to Java and attempting to code my first program. I haven't been able to get past the Tomcat set-up, however. I have a .jsp file in which I use a bean. I call the bean in this manner:


I'm using a class within a package. I've successully compiled the class from the command line, so I don't see any errors with it.

As for the set-up, I'm using Tomcat 6, and I've set my environment variables as follows:

CLASSPATH = .;%JAVA_HOME%;.;C:\Tomcat\lib\servlet-api.jar;C:\Tomcat\lib\jsp-api.jar;C:\Tomcat\lib\el-api.jar;C:\Servlets+JSP;..;..\..

PATH = %PATH%;%JAVA_HOME%\\bin

JAVA_HOME = C:\Program Files\Java\jdk1.6.0_06

CATALINA_HOME = C:\Tomcat

The error I receive when compiling is "the value for the useBean class attribute ... is invalid." When I refresh the page it say, "unable to load class."

I have my .jsp file in a folder under webapps and my .java and .class file in a folder named "data" (no quotes") in the classes directory under WEB-INF.

My class is declared public with private variables, and I do have a constructor.

I'm not sure if I have to modify the web.xml file or not. This is all new to me. Any help would be appreciated. I've been working on this for three days now.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Grins", please check your private messages for an important administrative matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ page import="data.search.*"%>
<jsp:useBean id="bean1" class="data.search" scope="session">
These two statements are saying conflicting things.

In the first, you are treating "search" as a package name. In the second, as a class name. Which is it?
 
Jean Jenkins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

Firstly, I apologize for the display name - I'll fix that.

Second, I'm confused. I thought in both instances I was referring to package.class. I have my naming convention/order wrong?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Grins:
Second, I'm confused. I thought in both instances I was referring to package.class. I have my naming convention/order wrong?


Firstly, code that doesn't follow accepted naming conventions is surprisingly hard to read. Package names should be all lowercase, and class names should be in mixed case. So it's hard to tell what your intention is.

In the import statement:You are telling the translator/compiler to include all classes in the data.search package. Here "search" is a package name.

Yet in:you are saying that "search" is a class in package "data". Which is it?

If "search" is a class, it should be named Search (in fact, it should be something a little more descriptive than a single word).

So what's the class and what's the package?
[ July 05, 2008: Message edited by: Bear Bibeault ]
 
Jean Jenkins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

The package is data, and the class is search.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your import statement is incorrect then. And again, standard Java naming conventions dictate that the class should be named Search rather than search.

So are you sure that the class file is in the appropriate place? (Assuming change to naming):

WEB-INF/classes/data/Search.class

?
 
Jean Jenkins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

I revised my class name and checked the path:

C:\Tomcat\webapps\ROOT\WEB-INF\classes\data

My Search.class file is in this location.

I think I've done this correctly. Interestingly, maybe you know what this means, I placed all of my .jsp files in the ROOT directory and left the class file in its current location. The application deploys fine now.

Any guesses?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No clue with the info I have available. Glad that it's working now.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!