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环境 ...
随机推荐
- MVC与三层架构
我们平时总是将三层架构与MVC混为一谈,殊不知它俩并不是一个概念.下面我来为大家揭晓我所知道的一些真相. 首先,它俩根本不是一个概念. 三层架构是一个分层式的软件体系架构设计,它可适用于任何一个项目. ...
- iOS开展——全球应对MotionEvent
遇到这样的要求:无论在哪个应用程序view controller,摇动手机,我们可以启动的方法. 你可以认为这个想法是使用包装的苹果"MotionEvent".但是,假如简单地把代 ...
- JAVA IP地址转成长整型方法
JAVA IP地址转成长整型方法 代码例如以下: /** * IP转成整型 * @param ip * @return */ public static Long ip2int(String ip) ...
- 问题:DataGrid该行并不总是很清楚验证错误(删除),
解决方案,如下面
转载,收藏转载请注明出处http://blog.csdn.net/metal1/article/details/37568391 景象:于DataGrid进数据有误,行验证返回new Validati ...
- Lua 脚本语法说明(转)
Lua脚本语法说明(增加lua5.1部份特性) Lua 的语法比较简单,学习起来也比较省力,但功能却并不弱. 所以,我只简单的归纳一下Lua的一些语法规则,使用起来方便好查就可以了.估计看完了,就懂得 ...
- HDU 1698 Just a Hook (段树更新间隔)
Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible thing for m ...
- 升级到tomcat8时Artifact SpringMvcDemo:war exploded: Server is not connected. Deploy is not
The method getDispatcherType() is undefined for the type HttpServletRequest 升级到tomcat8 http://segmen ...
- Encountered a section with no Package: header
刚才打开ubuntu,我的版本号是11.04.正想打开新立得软件工具包更新软件的时候,出现了例如以下错误: E:Encountered a section with no Package: heade ...
- 排序算法门外汉理解-Shell排序
#include <stdio.h> /* 希尔排序 基本思想:希尔排序又称为缩小增量排序,对简单插入排序的优化. (外部分组gap,组内部插入排序! ! ) 特点:一种不稳定的排序 */ ...
- ISAPI_Rewrite不起作用的N种原因
现在经常用到ISAPI_Rewrite,遇到的问题就是在本地测试的时候,一切没有问题,到服务器上,竟然不起作用.郁闷~经过我的一些探索,发现了比起作用的原因如下:1.IIS_WPG对ISAPI_Rew ...