例如你可以将JNDI配置放在一个叫jndi.properties中,在JSP调用,或者在STRUTS的ACTION中调用:
private static final String JNDIPROPERTIES_FILE = "com.aa.bb.cc";
String jndipropertiesfile = path + getInitParameter("jndi.properties.file");
System.setProperty(JNDIPROPERTIES_FILE,jndipropertiesfile);
在取上下文的时候:
    private void loadConfig() throws UOSException {
        //导入
        Properties properties = new Properties();
        FileInputStream fis = null;
        try{
            String fileName = System.getProperty(JNDIPROPERTIES_FILE);
            fis = new FileInputStream(fileName);
            properties.load(fis);
            _defaultContextFactory = properties.getProperty("java.naming.factory.initial");
            _defaultProviderUrl = properties.getProperty("java.naming.provider.url");
             _defaultPkgPrefixes = properties.getProperty("java.naming.factory.url.pkgs");
            _defaultSecurityPrincipal = properties.getProperty("java.naming.security.principal");
            _defaultSecurityCredentials = properties.getProperty("java.naming.security.credentials");
         }catch(java.io.FileNotFoundException ex){
            throw ex;
        }catch(java.io.IOException ex){
            throw ex
        }finally{
            if(fis!=null){
                try{
                    fis.close();
                }catch(IOException ex){
                }
            }
        }
    }
    后调用:
    public InitialContext getInitialContext(String contextFactory,
                                            String providerUrl,
                                            String pkgPrefixes,
                                            String username,
                                            String credentials)
        throws
        NamingException {
        StringBuffer ctxName = new StringBuffer();
        Properties props = new Properties();
        //设置工厂类
        if (contextFactory != null) {
            props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
                      contextFactory);
            ctxName.append(contextFactory);
        }
        //设置URL链接
        if (providerUrl != null) {
            props.put(javax.naming.Context.PROVIDER_URL, providerUrl);
            ctxName.append(providerUrl);
        }
        //设置URL连接的包前置名称
        if (pkgPrefixes != null) {
            props.put(javax.naming.Context.URL_PKG_PREFIXES, pkgPrefixes);
            ctxName.append(pkgPrefixes);
        }
        //设置用户名和密码
        if (username != null) {
            props.put(Context.SECURITY_PRINCIPAL, username);
            ctxName.append(username);            if (credentials != null) {
                props.put(Context.SECURITY_CREDENTIALS, credentials);
                ctxName.append(credentials);
            }
        }
        return  new javax.naming.InitialContext(props);
    }