Java EE (2)-Weblogic server performs JNDI bindings and lookups

Source: Internet
Author: User
Tags java web netbeans

1. System properties added by default on the application server

NetBeans Create Java Web Project (ctxtest) (index.jsp)

<%@page Import="java.util.Properties"%><%@page ContentType="text/html"pageencoding="UTF-8"%><!DOCTYPE HTML><HTML>    <Head>        <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">        <title>JSP Page</title>    </Head>    <Body>        <Table>            <% Properties props  =  system.getproperties ();  for (StringName:props.stringPropertyNames ()) {Out.println ("<tr><td>" +name+ ": </td><td>" +props.getproperty (name)+ "</td></tr>" ); }            %>        </Table>    </Body></HTML>

Visit:http://localhost:7001/ctxTest/index.jsp

2. File system Naming Service (requires Fscontext.jar and Providerutil.jar)

NetBeans Create Java Project (Fscontext): (Nameservicetest.java)

 PackageLee;Importjava.util.Hashtable;ImportJavax.naming.Context;ImportJavax.naming.InitialContext;Importjavax.naming.NamingException; Public classNameservicetest { Public Static voidMain (string[] args)throwsnamingexception{FinalString fileName = "00. Directory. docx"; FinalString dirName = "Codes"; Hashtable Env=NewHashtable (); Env.put (Context.initial_context_factory,"Com.sun.jndi.fscontext.RefFSContextFactory"); Env.put (Context.provider_url,"File:/d:/javaee traditional/fscontexttest"); Context CTX=NewInitialContext (env); Object file = ctx.lookup (fileName); System.out.println (FileName+ "name is bound to:" +file); System.out.println (The type of file is: "+File.getclass ()); Object dir = ctx.lookup (dirName); System.out.println (DirName+ "name is bound to:" +dir); System.out.println (The type of Dir is: "+Dir.getclass ());    Ctx.close (); }  }

Nameservicetest2.java

 PackageLee;Importjavax.naming.*;ImportJava.util.*; Public classnameservicetest2{ Public Static voidMain (string[] args)throwsnamingexception {FinalString fileName = "Youandme.mp3"; FinalString newName = "Oil and rice. mp3"; FinalString dirName = "Beyond"; FinalString NewDir1 = "NewDir1"; FinalString NewDir2 = "NewDir2"; Hashtable Env=NewHashtable (); Env.put (Context.initial_context_factory,"Com.sun.jndi.fscontext.RefFSContextFactory"); Env.put (Context.provider_url,"File://D:/JavaEE Traditional/fscontexttest/music"); Context CTX=NewInitialContext (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 ("------Below is the binding------under 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 (); }}        

2. Jndi Support for WebLogic

Java EE (2)-Weblogic server performs JNDI bindings and lookups

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.