Wednesday, August 31, 2005

Package for a Java Bean

This blog entry is for answering the question posted by Medha in the blog entry "Java Questions".

Question: Why do we need to declare a specific package name for all the beans we intend to use in JSP pages?
Answer: Even though the bean specification doesn't require it, I recommend that you always declare a specific package name for all beans you intend to use in JSP pages, via the Java package statement.

If you don't, you have to use the JSP import directive to import the bean class (with the page directive) in every JSP page that uses it. The page implementation class may use a vendor-dependent package name; since Java assumes that a class name without a package qualifier refers to a class in the same package as the class that uses it (or to a package declared by an import statement), the compiler looks for the bean class in the wrong package unless you explicitly import it.

I hope this clears your doubt, Medha.
Technorati Tags:
Blogs linking to this article

0 Comments:

Post a Comment

<< Home