1. 应用服务器默认添加的系统属性

NetBeans创建java web project(ctxTest) (index.jsp)

<%@page import="java.util.Properties"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<table>
<%
Properties props = System.getProperties();
for (String name : props.stringPropertyNames()) {
out.println("<tr><td>" + name + ": </td><td>" + props.getProperty(name) + "</td></tr>" );
}
%>
</table> </body>
</html>

访问:http://localhost:7001/ctxTest/index.jsp

2. 文件系统的命名服务 (需要fscontext.jar和providerutil.jar)

NetBeans创建java project(fsContext): (NameServiceTest.java)

package lee;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException; public class NameServiceTest {
public static void main(String[] args) throws NamingException{
final String fileName = "00.目录.docx";
final String dirName = "codes"; Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:/D:/JavaEE Traditional/FSContextTest"); Context ctx = new InitialContext(env); Object file = ctx.lookup(fileName);
System.out.println(fileName+ " 名称被绑定到: " + file);
System.out.println("file的类型是:" + file.getClass()); Object dir = ctx.lookup(dirName);
System.out.println(dirName + " 名称被绑定到: " + dir);
System.out.println("dir的类型是:" + dir.getClass()); ctx.close();
}
}

NameServiceTest2.java

package lee;

import javax.naming.*;
import java.util.*; public class NameServiceTest2
{
public static void main(String[] args) throws NamingException
{
final String fileName = "youandme.mp3";
final String newName = "油和米.mp3";
final String dirName = "Beyond";
final String newDir1 = "newDir1";
final String newDir2 = "newDir2"; Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file://D:/JavaEE Traditional/FSContextTest/music"); Context ctx = new InitialContext(env); try {
  ctx.rename(newName , fileName);
}
catch (Exception ex) {
} try {
  ctx.destroySubcontext(newDir1);
}
catch (Exception ex) {
} NamingEnumeration<Binding> bindings = ctx.listBindings("");
while(bindings.hasMore())
{
Binding binding = bindings.next();
System.out.println(binding.getName() + " --> " + binding.getObject());
} bindings = ctx.listBindings(dirName);
System.out.println("------下面是Beyond Context下的绑定------");
while(bindings.hasMore())
{
Binding binding = bindings.next();
System.out.println(binding.getName() + " --> " + binding.getObject());
} ctx.createSubcontext(newDir1);
ctx.createSubcontext(newDir2); ctx.destroySubcontext(newDir2);

ctx.rename(fileName , newName); ctx.close();
}
}

3. Weblogic的JNDI支持

Enviroment-->Servers-->AdminServer(admin)-->View JNDI Tree

NetBeans创建java web project(bindTest) (index.jsp)

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="javax.naming.*,javax.swing.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试JNDI绑定</title>
</head>
<body>
<%
Context ctx = new InitialContext(); final String TEST_JNDI = "testName";
java.util.Date date = new java.util.Date(); ctx.rebind(TEST_JNDI, date); out.println("<h3>JNDI绑定成功</h3>");
%>
</body>
</html>

访问:http://localhost:7001/bindTest/index.jsp

客户端程序JNDI查找:

NetBeans创建java project(jndiTest): (JNDIClient.java)

(需要webservices.jar和wlclient.jar)

package lee;

import java.util.*;
import javax.naming.*;
import javax.swing.*; public class JNDIClient { public static void main(String[] args) throws Exception {
final String INIT_FACTORY = "weblogic.jndi.WLInitialContextFactory";
final String WL_URL = "t3://localhost:7001"; Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY, INIT_FACTORY);
props.put(Context.PROVIDER_URL, WL_URL); // 如果需要安全控制,则需要如下两行代码
// props.put(Context.SECURITY_PRINCIPAL, "weblogic");
// props.put(Context.SECURITY_CREDENTIALS, "weblogic"); //初始化Context,使用InitialContext初始化Context
Context ctx = new InitialContext(props); //通过JNDI查找对象,该对象是一个java.util.Date对象。
Object obj = ctx.lookup("testName");
System.out.println(obj);
}
}

输出: Sat Jan 24 22:12:32 CST 2015

JavaEE(2) - Weblogic 服务器执行JNDI绑定和查找的更多相关文章

  1. JavaEE(1) - Weblogic 服务器管理的数据源

    JBoss下载: http://jbossas.jboss.org/downloads http://www.cnblogs.com/xw-cnblogs/articles/2439969.html ...

  2. WebLogic服务器

    WebLogic是美国Oracle公司出品的一个application server确切的说是一个基于JAVAEE架构的中间件,BEA WebLogic是用于开发.集成.部署和管理大型分布式Web应用 ...

  3. 转:配置nodemanager启动weblogic服务器

    下面仅供参考,里面表格还有文件目录我是写的linux,刚刚看到原作者是windows, 后面我会把自己配置nodemanager的经过记录上来,我搞得是linux. (一)通过nodemanager本 ...

  4. weblogic服务器的简单使用(一)

    一.前言 现在的公司开发的项目基于的平台是weblogic8.1.5,虽然版本是旧了点,但是用到的功能还是很多的,如JNDI.t3协议.EJB2.0.线程池.连接池.Ant部署.java远程调试. 发 ...

  5. [转]python3之paramiko模块(基于ssh连接进行远程登录服务器执行命令和上传下载文件的功能)

    转自:https://www.cnblogs.com/zhangxinqi/p/8372774.html 阅读目录 1.paramiko模块介绍 2.paramiko的使用方法 回到顶部 1.para ...

  6. [转帖]JavaEE中Web服务器、Web容器、Application服务器区别及联系

    JavaEE中Web服务器.Web容器.Application服务器区别及联系 https://www.cnblogs.com/vipyoumay/p/5853694.html 在JavaEE 开发W ...

  7. weblogic——服务器搭建与配置

    本次操作的内容:weblogic服务器搭建与配置服务 本次操作是主要围绕如何搭建weblogic服务器及配置服务,总共有两大步骤,可划分为六个小步骤: 选取已有环境,准备weblogic压缩包 安装w ...

  8. WebLogic服务器打补丁(11g/12c)

    转至:https://segmentfault.com/a/1190000019059894 背景 2019年04月17日,Oracle发布新季度安全公告.该安全公告披露WebLogic服务器存在多个 ...

  9. weblogic服务器内存溢出问题解决

    问题描述: 当我们在weblogic服务器一个域domain上面部署多个工程时,经常会出现内存溢出的情况:java.lang.OutOfMemoryError异常 原因:主要是因为weblogic环境 ...

随机推荐

  1. 【NO.3】 c program to caculate and display sum of two matrix

    source code: #include "stdafx.h" /* display sum of two matrix*/ int _tmain(int argc, _TCHA ...

  2. $(&#39;#checkbox&#39;).attr(&#39;checked&#39;); 回报checked或undefined该解决方案

    $('#checkbox').attr('checked'); 返回的是checked或者是undefined,不是原来的true和false了,有关此问题的解决方法例如以下 在JQ1.6之前的版本号 ...

  3. fullcalendar日历控件集合知识

    1.基本的语法: 首先,fullcalendar和JQUERY一样,以面向对象的方式来组织代码.当然,这里的面向对象不过指能够把整个fullcalendar理解为一个类,这个类里包含有非常多的属性.方 ...

  4. C标签之forEach

    <c:forEach>标签用于通用数据循环,它有下面属性 属 性 描 述 是否必须 缺省值 items 进行循环的项目 否 无 begin 開始条件 否 0 end 结束条件 否 集合中的 ...

  5. Zen Coding css,html缩写替换大观 快速写出html,css

    阅读本文,先仔细阅读网站文章. Zen Coding 快速编写HTML/CSS代码的实现 复制代码 代码如下:E 元素名称(div, p); E#id 使用id的元素(div#content, p#i ...

  6. 【转】介绍Jython,第一部分:轻轻松松写JAVA程序

    本文转自:http://www.ibm.com/developerworks/cn/education/java/j-jython1/index.html 关于本教程 本教程介绍哪些内容? 这个两部分 ...

  7. 第七章——DMVs和DMFs(1)

    原文:第七章--DMVs和DMFs(1) 简介: 从SQLServer2005开始,微软引入了一个名叫DMO(动态管理对象)的新特性,DMO可以分为DMFs(Dynamic Manage Functi ...

  8. 【转】Android 避免APP启动闪黑屏(Theme和Style)

    前几天Boss就反应说,机器每次启动程序都会闪一下黑屏,这个客户不接受.没办法,只能想想怎么解决,最后找到了下面的方法.闪黑屏的原因主要是我们启动Activity的时候,需要跑完onCreate和on ...

  9. 实现一个简单的boot

    1.汇编语言.分别汇编器和链接as86和ld86.码如下面: .globl begtext,begdata,begbss,endtext,enddata,endbss .text begtext: . ...

  10. SQL Server 2008 (R2) 单机版安装的先决条件

    原文:SQL Server 2008 (R2) 单机版安装的先决条件 出自:http://blogs.msdn.com/b/apgcdsd/archive/2012/03/07/sql-server- ...