JavaEE(2) - Weblogic 服务器执行JNDI绑定和查找
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绑定和查找的更多相关文章
- JavaEE(1) - Weblogic 服务器管理的数据源
JBoss下载: http://jbossas.jboss.org/downloads http://www.cnblogs.com/xw-cnblogs/articles/2439969.html ...
- WebLogic服务器
WebLogic是美国Oracle公司出品的一个application server确切的说是一个基于JAVAEE架构的中间件,BEA WebLogic是用于开发.集成.部署和管理大型分布式Web应用 ...
- 转:配置nodemanager启动weblogic服务器
下面仅供参考,里面表格还有文件目录我是写的linux,刚刚看到原作者是windows, 后面我会把自己配置nodemanager的经过记录上来,我搞得是linux. (一)通过nodemanager本 ...
- weblogic服务器的简单使用(一)
一.前言 现在的公司开发的项目基于的平台是weblogic8.1.5,虽然版本是旧了点,但是用到的功能还是很多的,如JNDI.t3协议.EJB2.0.线程池.连接池.Ant部署.java远程调试. 发 ...
- [转]python3之paramiko模块(基于ssh连接进行远程登录服务器执行命令和上传下载文件的功能)
转自:https://www.cnblogs.com/zhangxinqi/p/8372774.html 阅读目录 1.paramiko模块介绍 2.paramiko的使用方法 回到顶部 1.para ...
- [转帖]JavaEE中Web服务器、Web容器、Application服务器区别及联系
JavaEE中Web服务器.Web容器.Application服务器区别及联系 https://www.cnblogs.com/vipyoumay/p/5853694.html 在JavaEE 开发W ...
- weblogic——服务器搭建与配置
本次操作的内容:weblogic服务器搭建与配置服务 本次操作是主要围绕如何搭建weblogic服务器及配置服务,总共有两大步骤,可划分为六个小步骤: 选取已有环境,准备weblogic压缩包 安装w ...
- WebLogic服务器打补丁(11g/12c)
转至:https://segmentfault.com/a/1190000019059894 背景 2019年04月17日,Oracle发布新季度安全公告.该安全公告披露WebLogic服务器存在多个 ...
- weblogic服务器内存溢出问题解决
问题描述: 当我们在weblogic服务器一个域domain上面部署多个工程时,经常会出现内存溢出的情况:java.lang.OutOfMemoryError异常 原因:主要是因为weblogic环境 ...
随机推荐
- 创Wcf案例数据服务
首先,创建实体类: using System; using System.Linq; using System.Collections.Generic; using System.Data.Servi ...
- html5移动开发--js温馨提示
1.a标签执行js笔试 <a id="myID" href="javascript:myfuction();"></a> 2.实时监听i ...
- jq分页插件
jq分页插件 http://www.zhangxinxu.com/jq/pagination_zh/ html --------------- <tbody id="hiddenres ...
- JavaHTTP下载视频
控制层类: package com.grab.video.controller; import java.io.BufferedOutputStream; import java.io.Buffere ...
- 《Java程序猿面试笔试宝典》之Java与C/C++有什么异同
Java与C++都是面向对象语言,都使用了面向对象思想(比如封装.继承.多态等),因为面向对象有很多非常好的特性(继承.组合等),使得二者都有非常好的可重用性. 须要注意的是,二者并不是全然一样,以下 ...
- linux 脚本測试网络速度
example: ./netspeed eth0 1 #!/bin/bash 2 3 INTERVAL="1" # update interval in seconds ...
- freemarker错误九
1.错误叙述性说明 五月 30, 2014 11:52:04 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template p ...
- 使用 node-inspector 调试 Node.js
大部分基于 Node.js 的应用都是执行在浏览器中的, 比如强大的调试工具 node-inspector. node-inspector 是一个全然基于 Node.js 的开源在线调试工具,提供了强 ...
- 【Android进阶】Listview分页加载数据的实现
Listview分页加载数据的实现 public class MainActivity extends Activity { protected static final int SUCCESS_GE ...
- js比量undefined种类
js比量undefined种类 if (reValue== undefined) { alert("undefined"); } 发现推断不出来.最后查了下资料要用type ...