Win a copy of Java Challengers this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Tomcat6 and Java Beans

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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, http://www.blahblah.com/test.jsp works fine. How ever if I have with in a sub-directory /temp then http://www.blahblah.com/temp/test.jsp gives me an error saying TestClass cant be identified.

In tomcat5 I dont get any of these errors..

Cheers

CJ
 
cj jayamaha
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

cheers

CJ
 
Saloon Keeper
Posts: 23536
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic