JNDI/JCA ScrapbookResin 3.0
Resin 3.0

Orientation
Features
Installation
Configuration
Web Applications
JSP
Servlets and Filters
Portlets
Databases
Admin (JMX)
Amber
Security
XML and XSLT
XTP
Resources
Performance
Protocols
Third-party
Troubleshooting/FAQ

Library
Tutorials
Scrapbook
Tutorials
Resources
Performance

A repository of notes and comments that will eventually make their way into the documentation. Please treat the information here with caution, it has often not been verified.

  1. General
    1. Find web-app directory from JNDI bean?

General

Find web-app directory from JNDI bean?

In generic Servlet we can use ServletContext.getRealPath() to get real webapp's directory. And then we can use that to load configuration files.

But, suppose there is a JavaBean used via <resource-ref> tag in web.xml, is there anyway for the Bean to get the webapp's context directory? I hope not to hardcode the path in the web.xml.

Mattias Jiderhamn writes:

I solved a similar problem by having a load-on-startup servlet that in its init() puts the application root in another JNDI reference, like this:

 

public class InitServlet extends HttpServlet
{
  public void init() throws ServletException
  {
    ServletContext ctx = this.getServletContext();
    String contextRoot = ctx.getRealPath("/");
    System.out.println("  The real path of the application is: " + contextRoot);

 

    try
    {
      Context env = (Context) new InitialContext().lookup("java:comp/env");
      env.createSubcontext("ourApplication");
      env.rebind("ourApplication/application-root", contextRoot);
    }
    catch(NamingException nex)
    {
      nex.printStackTrace(System.err);
      throw new ServletException(nex);
    }
  }
}

        
 


Tutorials
Resources
Performance
Copyright © 1998-2003 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.