Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-dev] Accessing context bean from servlet

Hi,

I am not so familiar with jetty, so bare with me if i am asking silly
questions. (have j2ee experiences though)

I currently am developing i simple servlet to monitor and publish the
status of a software component. To do this, i have to read a property file
to determine the application configuration settings. Because i only want
to read the properties once at startup of the j2ee application i try to
read the properties in a bean and add the bean to the context.

            // Create contexthandler
            ServletContextHandler context = new
ServletContextHandler(ServletContextHandler.SESSIONS);
            context.setContextPath(icfHttpUri);
            server.setHandler(context);

            context.addServlet(new ServletHolder(new
IcfStatusServlet()),"/*");

            context.addBean(new icfServerBean());
            server.start();
            server.join();

This works fine, only i could not find how to access this bean added to
the context from within the servlet.

    @Override
    public void init(ServletConfig config) throws ServletException {

        super.init(config);


          ServletContext context = getServletConfig().getServletContext();

        ServletContext servletContext = config.getServletContext() ;


Any hints/suggestions ? I also could do this from within the servlet and
read the properties when a session parameter is not/re-set, but still want
to know how i can access this bean?

Cheers,
Peter



Back to the top