Web容器与应用服务器的整合

  当今的企业级开发中J2EE技术无疑是运用的最广泛的一种。在架设服务器的时候通常出现Web容器和应用服务器不在同一台主机的问题,这时我们可以通过配置Web容器中的web.xml文件来实现两段的联系。
在web.xml中我们添加入如下语句:
 <!-- weblogic url -->
 <env-entry>

  <description>url of Context parameter of invoke ejb</description>

   <env-entry-name>param/url</env-entry-name>
   <env-entry-value>t3://127.0.0.1:7001</env-entry-value>

   <env-entry-type>java.lang.String</env-entry-type>

 </env-entry>
我们按照该格式只要把地址设置好即可。
然后在编写一个获取该信息的工具类,在其中入如下代码:
    private InitialContext getInitialContext()
        throws Exception
    {
        String s;
        Object obj;
        Object obj1;
        InitialContext initialcontext = new InitialContext();
        s = (String)initialcontext.lookup("java:comp/env/param/url");
        obj = null;
        obj1 = null;
        Object obj2 = null;
        Properties properties;
        properties = new Properties();
        properties.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
        properties.put("java.naming.provider.url", s);
        if(obj != null)
        {
            properties.put("java.naming.security.principal", obj);
            properties.put("java.naming.security.credentials", obj1 != null ? ((Object) (obj1)) : "");
        }
        return new InitialContext(properties);

}
这里我们是已Weblogic为列,这样我们就能调到另一台机器上应用服务器的JNDI了
是不是很简单

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值