I have bean class named User. It’s not in a named package so I try to use this bean in a JSP page like this:
<jsp:useBean id="user" class="User" /> This doesn’t work. I get a message about class User not being found. Just to test, I replaced my class name with “java.util.Date”, and then the page was accepted. Do I have to put the class in a package? |
Answer: JDK 1.4 update: In Sun’s JDK 1.4 compiler, you can no longer import any type from the unnamed package into a class in a named package. In other words, your beans really must be part of a package. For details, see Sun’s Bug Parade. The rest of this answer is valid for previous versions of Sun JDKs and possibly for other compilers such as Jikes.The reason the JSP container can not find your bean when it’s not part of a package has to do with how Java in general resolves references to classes references through their short name. I describe this in an article at the O’Reilly site:
There are other tips in this article that you may find useful, so please read it when you get a chance. |