• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is this error?

 
Arun, Shanmugham
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a Simple Bean class. The class is not in a package. When i tried using it . I got the error that
"Class not found". But the same is working after bring it in a package. Will the bean work without package.
Arun
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is my understanding the Beans' have to be in a package inorder for them to work...at least with the Tomcat container. I don't know about other web servers
Bosun
 
Arun, Shanmugham
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bosun
hope i will get some more detail on it.
Arun

 
Phil Hanna
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bosun is correct, but this is really a bug in Tomcat.
The Tomcat (Jasper) JSP container generates servlet source code for your JSP. As part of this, it generates a "package" statement at the top, one that maps to your directory structure. However, this means if you use an unqualified class name in the code anywhere, it is assumed to be either (1) part of the same package as the generated JSP, or (2) found in the import list. Since your bean is neither, you get a compilation error.
There is an easy workaround, however. You can explicitly specify your bean in a page import directive:
<%@ page import="MyBean" %>
...
<jsp:useBean id="x" class="MyBean"/>
It's a little easier to see what I mean if you look at the generated servlet source code in your Tomcat/work directory.
I would emphasize again that this restriction is not part of the JSP specification, it is a Tomcat bug. JRun 3.0 has no such problem, for example, because it doesn't create a package statement.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
Website: http://www.philhanna.com
 
Arun, Shanmugham
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks Phil, I got ur Point. May be i'll use JRun in case needed.
Regards
Arun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic