jQuery in Action, 3rd edition
The moose likes JSP and the fly likes Organizing large JSP into smaller chunks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Organizing large JSP into smaller chunks" Watch "Organizing large JSP into smaller chunks" New topic

Organizing large JSP into smaller chunks

Robin Clark
Ranch Hand

Joined: Dec 17, 2003
Posts: 81
I am trying to organize a very large JSP into smaller more organized chunks. However, when I implement some of the functionality in a separate java class, my jsp will not compile successfully because it can not see the new class. I have successfully compiled the java class and installed the .class file in my web application's WEB-INF/classes directory. I even created a jar file with the new class and placed it in the web application's WEB-INF/lib directory and the Tomcat common/lib directory. I've stopped and started Tomcat as well.
Here is an excerpt from the jsp:

The error that I get is when compiling the last statement that instantiates the UtteranceInfo object. The error message is:

Here is an excerpt for the code for the UtteranceInfo class:
Robin Clark
Ranch Hand

Joined: Dec 17, 2003
Posts: 81
I accidently submitted that post before I finished editting it. Here is the correct code excerpt from the UtteranceInfo class:

This is the first time that I have ever tried to instantiate a java class from within my jsp. I am using Tomcat 4.0.6 on Windows 2000 server.
Thank you very much for your help.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

You need to put the class in a package other than the nameless "default" package.

[Asking smart questions] [About Bear] [Books by Bear]
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
And you probably also need to add another line
<%@page import="whatever.UtteranceInfo"%>
so that your JSP knows where to look for the class.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Robin Clark
Ranch Hand

Joined: Dec 17, 2003
Posts: 81
Thank you. I am having trouble putting these pieces together. I have created a new directory WEB-INF/classes/utterance. In this directory is my .class file for my java class. I changed the java class to add a package statement to the top. Is this the correct syntax for the package statement?

In my jsp, I added an import directive like this:

I bounced Tomcat, but I still get the following error when I try to execute
my jsp in a browser:

I am confused a bit further because I am trying to do this in Eclipse and I don't understand what it is doing when I try to create a new package, "utterance" under the WEB-INF/classes directory when my project is at the web application root level. What it does is create a directory under the web application root level for the .java file, then it places the .class file in the WEB-INF/classes/utterance directory. But I guess that question should be directed to the IDE forum.
Any help would be greatly appreciated.
Robin Clark
Ranch Hand

Joined: Dec 17, 2003
Posts: 81
I think that I figured this out. My import directive in the jsp was wrong. It should have been:

I think that I am trying to learn too many new things at one time:
I agree. Here's the link: http://aspose.com/file-tools
subject: Organizing large JSP into smaller chunks
It's not a secret anymore!