• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP not accessing a bean without a package  RSS feed

 
Kishan Kumar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I would like to know the reason why a JSP cannot access a java class residing the classes directory under WEB-INF. Iam using Tomcat server
and when I write a bean without any package and place it in classes directory, the JSP is not able to resolve the reference. When I add a package and put my java class in it, the JSP all of a sudden recognizes it.. Why is creation of a package forced for JSP to recognize ??. Any classloader feature that could give an explanation for this ??.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the class is not in a package, the loader looks in the
same package (location) as that of the derived servlet.
But we, ofcourse, know it is not there, hence the behavior.
When you add the class to the package, it knows exactly
where to look for. I haven't done JSPs in a while (read > 1 yr)
so I may scrapping my memory to say this and hence I can't
be really precise. Anyways, that's the jist of it.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version and container you are using?
I did the same thing 1/2 year ago, at that moment, I use Tomcat 4.1.27 and it works fine.
Maybe newer versions or different containers require some specific configuration.
Nick.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, without a package the JVM looks in the "current" directory - which you have no control over. Just bite the bullet and put ALL classes having to do with servlets or JSP in a package. You will be glad you did.
Bill
 
Kishan Kumar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the explanation. Is "classes" directory not in tomcat's classpath ??. Unpackaged java classes are anyway expected to be directly under the directory mentioned in the classpath. Even if we say
packagename.classname, classloader can recognize only if kept under a directory mentioned in the classpath rt ??. If "classes" directory is not in the classpath how can JSP recognize the package under the classes directly.
This is ofcourse how we understand while we learn JDK. Does this change in a J2EE Environment. Can you direct me to articles which talks about say How J2EE recognizes classes ??. Iam using Tomacat 4.1.24
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!