aspose file tools*
The moose likes Servlets and the fly likes How to acess a packaged bean in a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to acess a packaged bean in a servlet" Watch "How to acess a packaged bean in a servlet" New topic
Author

How to acess a packaged bean in a servlet

Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410

I have stored the bean class in the destination derictory of my server from where my jsp page locates it and for that i had to make my beans as a packaged one
like this adding this line before import statements of my bean
package sunexamples.beans;
because my bean is in sub-directory of sunexapmples which is beans and my bean class resides there
Now If i want to use the same bean class in side my servlet I am giving its full path name but it is not able to locate it
I tried calling it through this way
sunexamples.beans.mybean b = new sunexamples.beans.mybean();
and this way also
classes.sunexamples.beans.mybean b =
new classes.sunexamples.beans.mybean();
but compiler is not able to locate it
Im totally confused how to access my bean through servlet


SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

Sounds like a classpath problem.
Make sure the directory containing sunexamples is in the classpath for the servlet container.
Also in your servlet, you can import your package. Then you won't need to reference yourbean by the whole package name everytime.


!_I_Know_Kung_Fu_!
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
I imported the package also
actually I am using javawebserver2.0
and
this bean is in directory
c:\javawebserver2.0\classes\sunexamples\beans
I am trying to import the package sunexamples.beans
like import classes.sunexamples.beans; or
import sunexamples.beans;
then it says cannot resolve symbol beans (compiler error)
I tried setting my classpath by adding a line in front of existing classpath like this
c:\javawebserver2.0\classes\sunexamples\beans
(I m using Windows NT)
still nothing seems to work


Originally posted by Andrew Shafer:

Sounds like a classpath problem.
Make sure the directory containing sunexamples is in the classpath for the servlet container.
Also in your servlet, you can import your package. Then you won't need to reference yourbean by the whole package name everytime.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to acess a packaged bean in a servlet