This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Is it mandatory to put a bean inside a package? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Is it mandatory to put a bean inside a package?" Watch "Is it mandatory to put a bean inside a package?" New topic
Author

Is it mandatory to put a bean inside a package?

Ramdas Sawant
Ranch Hand

Joined: Aug 08, 2005
Posts: 51
Hi all,
I have written one bean & placed the class file of the same bean in the WEB-INF/classes folder. The bean is not in any package, but it is in default package.i.e there is no package statement in the bean's java file.Now i want to use the same bean in a jsp. Now when i try to instantiate the bean i am getting the error. The jsp engine is not able to find the class. i tried to import the class, but still got another error.
Now when i put the bean in a package and try to use it in the jsp, it worked fine.

Question : Is it mandatory to put a bean inside a package ?

Thanks
Ramdas.


If you think you can, you can. If you think you can't, you are right.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

As of Java 1.4, yes.
It's mandatory.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ramdas Sawant
Ranch Hand

Joined: Aug 08, 2005
Posts: 51
Hi Ben,
Thanks for the response. Can u/anyone explain why is it so..
Waiting for explaination ..

Regards
Ramdas
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Because as of Java 1.4 there is no means to import a non-packaged class.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ramdas Sawant
Ranch Hand

Joined: Aug 08, 2005
Posts: 51
Thanks Bear.

Ramdas
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Furthermore - the convention for the JVM finding a default package class is to look in the "current" directory. In a server environment you have no control over the "current" directory so you have to use a package.
Bill
 
Don't get me started about those stupid light bulbs.
 
subject: Is it mandatory to put a bean inside a package?
 
Similar Threads
importing a package
bean always should be in package ?
UseBean error
jBoss and JRun
Changing ClassPath