JSP compilation error

I have a jsp that instantiates an object of a class and invokes a method on it. The class is not within any package. Therefore the class file was created straightway inside the WEB-INF/classes folder and not within any sub-folder of classes folder. When I run the JSP, it gives compilation error as it is unable to resolve the class symbol. However if I place the class within package, the JSP runs. What could be the possible reason?

[441 byte] By [maitya] at [2007-11-26 15:12:28]
# 1

You are right, I tested this case with the following code:

<%--

<jsp:useBean id="noPackageBean" class="NoPackageBean"/>

<jsp:setProperty name="noPackageBean" property="id" value="9898"/>

<jsp:setProperty name="noPackageBean" property="name" value="Sunshine"/>

<jsp:getProperty name="noPackageBean" property="name"/>

--%>

<jsp:useBean id="anotherBean" class="somepackage.AnotherBean"/>

<jsp:setProperty name="anotherBean" property="aid" value="5564"/>

<jsp:setProperty name="anotherBean" property="aname" value="Moonshine"/>

<jsp:getProperty name="anotherBean" property="aname"/>

The part that's commented out gave an

org.apache.jasper.JasperException: Unable to compile class for JSP

But if you look at the syntax for jsp:useBean it says class="package.class"

http://java.sun.com/products/jsp/syntax/2.0/syntaxref2027.html#8865

This means that all beans you try to reference from inside a JSP *must* be inside a package.

Was there a particular reason why you did not want a class in a package?

appy77a at 2007-7-8 9:03:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
The reason is that since java1.4, classes in the "unnamed" package have not been visible to classes within a "named" package.Go read all the sordid details here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4361575Cheers,evnafets
evnafetsa at 2007-7-8 9:03:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

The solution they suggest for the bug is "To fix such problems in your code, move all of the classes from the unnamed namespace into a named namespace."

And, in the comments a few people find that it's a problem to have such a restriction, I wonder if they'll fix the bug to allow packageless classes depending on feedback.

appy77a at 2007-7-8 9:03:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...