aspose file tools
The moose likes JSP and the fly likes Tomcat6 and Java Beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Tomcat6 and Java Beans" Watch "Tomcat6 and Java Beans" New topic

Tomcat6 and Java Beans

cj jayamaha

Joined: Aug 26, 2008
Posts: 12

I have searched for a solution for this issue for days and has not been able to find any so I am hoping one of your guys will be able to help me here..

imagine the following code is in a file called test.jsp

pacakge.test.TestClass class = new pacakge.test.TestClass();

In tomcat6 if I have the file in the root folder, works fine. How ever if I have with in a sub-directory /temp then gives me an error saying TestClass cant be identified.

In tomcat5 I dont get any of these errors..


cj jayamaha

Joined: Aug 26, 2008
Posts: 12
aha aha aha..

Did anyone know that the Web-INF folder have to be copied to all the sub-folders that accesses the beans in order for the beans to work from sub-folders?

Anyway, turns out that is the solution, so I copied my main WEB-INF folder to all the sub-dirs that has jsp using beans and it is working fine.

But this is a pain in the ass... is there a shortcut? or there a solution (another one) or am I barking up the wrong tree?


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16388

You're definitely barking up the wrong tree. If your class files are in their proper location under WEB-INF/classes - or in a JAR in WEB-INF/lib, every JSP in the webapp should see them just fine. That's the way the standard is defined.

As for any other webapp, no. Webapps are supposed to be self-contained. They can't share their toys If you want to share a class between webapps, you have to put it in an inherited classpath such as the server's classpath, which means CATALINA_HOME/lib or someplace like that. Or it may be off CATALINA_BASE. I can never keep the two straight, since usually they're the same place.

Anyway, welcome to the JavaRanch!

Customer surveys are for companies who didn't pay proper attention to begin with.
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

It sounds to me like you were using the <Tomcat Home>/webapps/ folder as the ROOT path, and placing all your data in there. This is a nono. Your ROOT path should be: <TOMCAT HOME>/webapps/ROOT/.

Why? The Root path (that you get to like http://localhost:8080/) is the default Context. But any folders put in the <Tomcat Home>/webapps/ path will be considered a NEW Context and so will need a new WEB-INF folder (and will have trouble talking with servlets/jsps/sessions in other Contexts). Each Context is considered a new Application.

If you want all you folders to be part of the same application then you should put all the folders in <Tomcat Home>/webapps/ROOT/. Anything that should be a different application should be in a different folder under <Tomcat Home>/webapps/.

Some examples:
I want to access http://localhost:8080/index.jsp
index jsp should be in <Tomcat Home>/webapps/ROOT/index.jsp
index jsp accesses a servlet mapped to http://localhost:8080/Process
The servlet should be in <Tomcat Home>/webapps/ROOT/WEB-INF/classes/<package>/Process.class
The Process servlet forwards to a URL http://localhost:8080/temp/alldone.jsp
alldone.jsp should be in <Tomcat Home>/webapps/ROOT/temp/alldone.jsp

Later, I decide that in addition to my main application listed above, I have another, INDEPENDENT application called accounting which I access through http://localhost:8080/accounting/accountHome.jsp. Because it is a new application I need to make a new directory under <Tomcat Home>/webapps/ and give it a new WEB-INF directory.
accountHome.jsp should be in <Tomcat Home>/webapps/accounting/accountHome.jsp
accountHome accesses a JavaBean to get some data.
The Bean should be in <Tomcat Home>/webapps/accounting/WEB-INF/classes/<package>/AccountManager.class

I hope I helped more than confused with that :-)

cj jayamaha

Joined: Aug 26, 2008
Posts: 12
Gee, guys thanks, I am glad to be here...

Right, You see it is all honky-dory on my local machine but this problem comes up on the server. I am starting to think it is with the hosting company. I ll take it up with them.

thanks guys,
It is sorta covered in the JavaRanch Style Guide.
subject: Tomcat6 and Java Beans