This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Java Products and Servers and the fly likes Access a context bean from servlet in Jetty 8 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Access a context bean from servlet in Jetty 8" Watch "Access a context bean from servlet in Jetty 8" New topic
Author

Access a context bean from servlet in Jetty 8

Peter van Nes
Greenhorn

Joined: Jun 09, 2010
Posts: 23
Hi,

I am trying a simple servlet based on Jetty 8. In the main class where i create the server instance and add the servlet i want to fill and add a bean with configuration data which is read and stored in the bean at startup.

The bean is added using the addBean method of context.




Is it possible to access the bean from within the servlet ? I can get the ServletContext but have not found any clue how to retrieve the bean added to the context from within the servlet.



Any hints / Tips ?
Cheers,
Peter
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

There is no addBean() method to the ServletContext, so it's not clear what context you are asking about.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter van Nes
Greenhorn

Joined: Jun 09, 2010
Posts: 23
Hi Bear,

I can add a bean to the ServletContextHandler to which a new servlet is added.



Now i want to access the bean added to the ServletContextHandler from the servlet.
I tried to access it through the servlet context from within the servlet.





Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

Never heard of ServletContextHandler. Apparently it's proprietary to Jetty. I've moved this to a more appropriate forum.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Access a context bean from servlet in Jetty 8
 
Similar Threads
Spliting Spring Configurations
Managed beans aren't constructed running on JBoss 5.1.0 (works fine with Tomcat 6)
strange contextpath problem
can anyone explain getServletContext method..
ServletContext Null pointer Exception