• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it mandatory to put a bean inside a package?

 
R Sawant
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As of Java 1.4, yes.
It's mandatory.
 
R Sawant
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because as of Java 1.4 there is no means to import a non-packaged class.
 
R Sawant
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear.

Ramdas
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic