⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lookup.html

📁 jdbc书
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE>Writing Advanced Applications, Chapter 4: Distributed Computing</TITLE>
  <META NAME="AUTHOR" CONTENT="Monica Pawlan and Calvin Austin">
  <META NAME="KEYWORDS" CONTENT="programming, advanced, Java 2">
  <META NAME="OWNER" CONTENT="Editorial/JDC">
  <META NAME="revision" CONTENT="@(#)lookup.src   1.3 05/11/99  JDC">
</HEAD>

<!-- Start Body Insert-->
<BODY BGCOLOR="#ffffff">
<!-- End Body Insert-->

<!-- Start PageTop Insert -->

<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
  <TR ALIGN="CENTER" VALIGN="TOP">
    <TD WIDTH="157" ALIGN="LEFT">
    <IMG SRC="/images/pixel.gif" HEIGHT="40" WIDTH="40" ALT="">
    <A HREF="http://java.sun.com/index.html"><IMG SRC="/images/javalogo52x88.gif" WIDTH="52" HEIGHT="88" ALT="Java Technology Home Page" BORDER="0"></A>
    <BR>
    <IMG SRC="/images/pixel.gif" WIDTH="157" HEIGHT="1" ALT=""></TD>

    <TD>

    <FORM NAME="seek1" METHOD="GET" ACTION="http://search.java.sun.com/query.html">
    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
      <TR>
        <TD ALIGN="RIGHT">
        <IMG SRC="/images/stripelt.gif" WIDTH="6" HEIGHT="14" ALT=""></TD>
        
        <TD WIDTH="100%">
        
        <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
          <TR>
            <TD BGCOLOR="#CC9966" WIDTH="100%">
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD>
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD BGCOLOR="#CC9966">
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD>
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD BGCOLOR="#CC9966">
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD>
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD BGCOLOR="#CC9966">
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
        </TABLE>
        </TD>
        
        <TD ALIGN="LEFT">
        <IMG SRC="/images/stripert.gif" WIDTH="6" HEIGHT="14" ALT=""></TD>

        <TD>
        
        <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
          <TR>
            <TD VALIGN="CENTER">
            <A HREF="http://java.sun.com/a-z/index.html"><IMG SRC="/images/azindex.gif" BORDER="0" WIDTH="72" HEIGHT="11" ALT="A-Z Index"></A></TD>
              
            <TD VALIGN="CENTER">
            <FONT FACE="Helvetica" SIZE="1">
            <INPUT TYPE="text" SIZE="15" MAXLENGTH="128" NAME=qt></FONT></TD>
            
            <TD VALIGN="CENTER">
            <INPUT TYPE="image" SRC="/images/search.button.gif" 
              value="search" BORDER="0" WIDTH="55" HEIGHT="14" ALT="Search"></TD>
          </TR>
        </TABLE>
        </TD>
      </TR>
    </TABLE>
    </FORM>
    <P>

    <TABLE BORDER="0" WIDTH="100%" CELLPADDING="0" CELLSPACING="0">
      <TR VALIGN="TOP">
        <TD WIDTH="100%"><IMG SRC="/images/chiclet.row.gif" WIDTH="55" 
          HEIGHT="18" ALT=""></TD>
          
        <TD ROWSPAN="4" ALIGN="RIGHT" WIDTH="152">
        <A HREF="/developer/index.html"><IMG SRC="/images/developer.connection.header.gif" BORDER="0" HEIGHT="42" WIDTH="319" ALT="Java Developer Connection(SM)"></A></TD>
      </TR>
      
      <TR VALIGN="TOP">
        <TD BGCOLOR="#FFFFFF" HEIGHT="1" WIDTH="100%">
        <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
      </TR>
      
      <TR VALIGN="TOP">
        <TD BGCOLOR="#CC9966" HEIGHT="1" WIDTH="100%">
        <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
      </TR>
      
      <TR VALIGN="TOP">
        <TD><A HREF="/developer/onlineTraining/"><IMG SRC="/images/online-training.gif" ALT="Online Training" BORDER=0></A></TD>
      </TR>
    </TABLE>

    </TD>
  </TR>
</TABLE>

<!-- End PageTop Insert -->

<!-- Start NavBar Insert -->
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3" BGCOLOR="#FFFFFF" WIDTH="157" ALIGN="LEFT">

<!-- tab categories -->

<TR>
<TD><A HREF="http://java.sun.com/products/"><IMG SRC="/images/side.tab.products.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Downloads, APIs, Documentation"></A></TD>
</TR>

<TR>
<TD><A HREF="/developer/index.html"><IMG SRC="/images/side.tab.developer.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Java Developer Connection"></A></TD>
</TR>

<TR>
<TD><A HREF="/developer/infodocs/index.shtml"><IMG SRC="/images/side.tab.docs.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Tutorials, Tech Articles, Training"></A></TD>
</TR>

<TR>
<TD><A HREF="/developer/support/index.html"><IMG SRC="/images/side.tab.support.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Online Support"></A></TD>
</TR>

<TR>
<TD><A HREF="/developer/community/index.html"><IMG SRC="/images/side.tab.community.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Community Discussion"></A></TD>
</TR>

<TR>
<TD><A HREF="http://java.sun.com/industry/"><IMG SRC="/images/side.tab.news.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="News &amp; Events from Everywhere"></A></TD>
</TR>

<TR>
<TD><A HREF="http://java.sun.com/solutions"><IMG SRC="/images/side.tab.solutions.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Products from Everywhere"></A></TD>
</TR>

<TR>
<TD><A HREF="http://java.sun.com/casestudies"><IMG SRC="/images/side.tab.case.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="How Java Technology is Used Worldwide"></A></TD>
</TR>

<TR><TD>&nbsp;</TD></TR>


<!-- End NavBar Insert -->


<!-- START SUB-NAV -->

<TR>
  <TD><!-- INSERT SUB-NAV INFO -->
  </TD>
</TR>


<!-- END SUB-NAV -->

</TABLE>

<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR>
<TD>

<!-- Template Version 2.0 -->

<!-- ================== -->
<!-- Start Main Content -->
<!-- ================== -->



<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR>
<TD VALIGN="TOP">
<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

  <A NAME="top"></A>
  <DIV ALIGN="RIGHT">
  <FONT SIZE="-1"><A HREF="/developer/onlineTraining/index.html">Training Index</A></FONT>
  <H2>Writing Advanced Applications<BR>
  <FONT SIZE="3">Chapter 4: Lookup Services</FONT></H2>

  <FONT SIZE="-1">[<A HREF="dist.html">&lt;&lt;BACK</A>] [<A HREF="index.html#contents">CONTENTS</A>] [<A HREF="rmi.html">NEXT&gt;&gt;</A>]</FONT></DIV>

<P>
Lookup services enable communications over a network. A client
program can use a lookup protocol to get information on remote
programs or machines and use that information to establish
a communication.

<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">One common lookup service you might already be familiar with is Directory Name Service (DNS).
It maps Internet Protocol (IP) addresses
to machine names. Programs use the DNS mapping to look up the IP address
associated with a machine name and use the IP address to establish
a communication.</FONT>

<P>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">In the same way, the <A HREF="./Code/auction/AuctionServlet.java">AuctionServlet</A>
presented in <A HREF="code.html">Chapter 2</A> uses the naming service
built into the Enterprise JavaBeans<FONT SIZE="-2"><SUP>TM</SUP></FONT> architecture to look up
and reference Enterprise Beans registered with the Enterprise
JavaBeans<FONT SIZE="-2"><SUP>TM</SUP></FONT> server.</FONT>
</UL>

<P>
In addition to naming services, some lookup protocols provide directory
services. Directory services such as Lightweight Directory Access Protocol
(LDAP) and Sun's NIS+ provide other information and services beyond
what is available with simple naming services. For example, NIS+ associates
a <CODE>workgroup</CODE> attribute with a user account. This attribute can
be
used to restrict access to a machine so only the users in the specified
<CODE>workgroup</CODE> have access.

<P>
This chapter describes how the Java<FONT SIZE="-2"><SUP>TM</SUP></FONT> Naming and Directory Interface
(JNDI)
is used in the auction application to look up Enterprise Beans. It also
explains how to use some of the many other lookup services that have
become available over time. The code to use these other services is not as
simple as the lookup code in the auction application in Chapter 2, but
the advantages to these other services can outweigh the need for more
complex code in some situations.

<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#jndi">Java Naming and Directory Interface (JNDI)</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#corba">Common Object Request Broker Architecture (CORBA)
Naming Service</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#ior">Interoperable Object References (IOR)</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#rmi">Remote Method Invocation (RMI)</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#iiop">RMI Over Internet Inter-ORB Protocol (IIOP)</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#jini">JINI Lookup Services</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#perf">Improving Lookup Performance</A></FONT>
</UL>

<HR>

<A NAME="jndi"></A>
<H3>Java Naming and Directory Interface (JNDI)</H3>

<P>
The JNDI application programming interface (API) makes it easy to plug
lookup services from various providers into a program written in the
Java language. As long as the client and server both use the same lookup
service, the client can easily look up information registered with
the server and establish communication.


<P>
The auction application session Beans use JNDI and a special JNDI naming factory
from BEA Weblogic to look up entity Beans. JNDI services normally initialize the 
naming factory as a property on the command line or as an initialization value.

<P>
First, the naming factory <CODE>weblogic.jndi.TengahInitialContextFactory</CODE>
is put into a <CODE>java.util.Property</CODE> object, then the
<CODE>Property</CODE> object is passed as a parameter to the
<CODE>InitialContexT</CODE> constructor.  Here is an example <CODE>ejbCreate</CODE> method.

<PRE>
  Context ctx; //JNDI context

  public void ejbCreate() 
	throws CreateException, RemoteException {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, 
     "weblogic.jndi.TengahInitialContextFactory");
    try{
     ctx = new InitialContext(env);
    }catch(Exception e) {
     System.out.println("create exception: "+e);
    }
  }
</PRE>

Once created, the JNDI context is used to look up Enterprise Bean home
interfaces. In this example, a reference to the Enterprise Bean bound
to the name <CODE>registration</CODE> is retrieved and used for further
operations.

<PRE>
  RegistrationHome rhome =
        (RegistrationHome) ctx.lookup("registration");
  RegistrationPK rpk=new RegistrationPK();
  rpk.theuser=buyer;
  Registration newbidder =

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -