Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / September 2003

Tip: Looking for answers? Try searching our database.

How to access a bean from a servlet

Thread view: 
neoivan - 09 Sep 2003 00:59 GMT
I set a bean in servlet 1 like this:

       ServletContext context = config.getServletContext();

//    Instantiating the DbBean
       DbBean dbBean = new DbBean();
       
//    Initialize the DbBean's fields
//        dbBean.setDbUserName(config.getInitParameter("dbUserName"));
//        dbBean.setDbPassword(config.getInitParameter("dbPassword"));

//    put the bean in the servlet context
//      the bean will be accessed from JSP
       context.setAttribute("dbBean", dbBean);

My question is, how can i access this bean from another servlet, not a
JSP but a servlet?
Johann Burkard - 09 Sep 2003 19:50 GMT
neoivan schrob:
>         ServletContext context = config.getServletContext();

[...]

>         context.setAttribute("dbBean", dbBean);
>
> My question is, how can i access this bean from another servlet, not a
> JSP but a servlet?

By DBBean bean = (DBBean) context.getAttribute("dbBean"); if thats what you
meant.

Johann
Signature

If you had arguments, you wouldn't need to declare your discussion partner
a residental kook.
(Das Enezian ?ber sich in <3D8962F7.55C9429C@munged.adresses>)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.