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

📄 code3.html

📁 jdbc书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE>Writing Advanced Applications, Chapter 2: Entity and Session
Beans</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="@(#)proj.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>
<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 2 Continued: Entity and Session Beans</FONT></H2>

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

<P>
The example uses two entity Beans and two session Beans.
The entity Beans, <CODE>AuctionItemBean</CODE> and 
<CODE>RegistrationBean</CODE>, represent persistent items that 
could be stored in a database, and the session Beans,
<CODE>SellerBean</CODE> and <CODE>BidderBean</CODE>, 
represent short-lived operations with the client and data. 

<P>
The session Beans are the client interface to the entity beans. The SellerBean
processes requests to add new auction items for sale. The BidderBean processes
requests to retrieve auction items and place bids on those items.
Changing and adding to the database data in a container-managed Bean is left 
to the entity Beans.  

<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#servlet">Auction Servlet</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#entity">Entity Beans</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#session">Session Beans</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#container">Container Classes</A></FONT>
</UL>

<HR>

<A NAME="servlet"></A>
<H3>AuctionServlet</H3>

The <A HREF="./Code/auction/AuctionServlet.java">AuctionServlet</A>
is essentially the second tier in the application and the focal point for 
auction activities. It accepts end user 
input from the browser by way of hypertext transfer protocol
(<CODE>HTTP</CODE>), passes the input to the appropriate Enterprise
Bean for processing, and displays the processed results to the end user 
in the browser. 

<P>
Here is a 
<A HREF="http://www.rational.com/uml/resources/documentation/notation/notation5a.jtmpl">Unified Modeling Language (UML)</A>
class diagram for the <CODE>AuctionServlet</CODE> class. 

<P>
<IMG SRC="./Art/classes.gif">

<P>
The <CODE>AuctionServlet</CODE> methods shown above invoke
business logic that executes on the server by looking up an 
Enterprise Bean and calling one or more of its methods. When 
the servlet adds 
<CODE>HTML</CODE> codes
to a page for display to the user, that logic executes on the client.  

<P>
For example, the <CODE>listAllItems(out)</CODE> method 
executes code on the client to dynamically generate an <CODE>HTML</CODE> 
page to be viewed by the client in a browser. The <CODE>HTML</CODE> page is 
populated with the results of a call to <CODE>BidderBean</CODE> 
that exeuctes logic on the server to generate a list of all auction items.

</FONT>

<PRE>
private void listAllItems(ServletOutputStream out) 
				throws IOException{

//Put text on HTML page
  setTitle(out, "Auction results");
  String text = "Click Item number for description 
		and to place bid.";
  try{
     addLine("&lt;BR&gt;"+text, out);
//Look up Bidder bean home interface.
     BidderHome bhome=(BidderHome) ctx.lookup("bidder");
//Create Bidder bean remote interface.
     Bidder bid=bhome.create();
//Call Bidder bean method through remote interface.
     Enumeration enum=(Enumeration)bid.getItemList();

     if(enum != null) {
//Put retrieved items on servlet page.
       displayitems(enum, out);
       addLine("", out);
     }
  } catch (Exception e) {
//Pring error on servlet page.
     addLine("AuctionServlet List All Items error",out);
     System.out.println("AuctionServlet &lt;list&gt;:"+e);
  }
     out.flush();
}
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif"> 

<A NAME="entity"></A>
<H3>Entity Beans</H3>

<CODE>AuctionItemBean</CODE> and <CODE>RegistrationBean</CODE>
are entity Beans. <CODE>AuctionItemBean</CODE> 
adds new auction items to the database and updates the
bid amount as users bid on the item. <CODE>RegistrationBean</CODE>
adds information to the database on registered users. Both
Beans consist of the classes described here.  

<H4>AuctionItem Entity Bean</H4>

Here are the <CODE>AuctionItemBean</CODE> classes. Remember that these
Enterprise Beans are distributed objects that
use the Remote Method Invocation (RMI) API, so when
an error occurs, an RMI remote exception is thrown.

<UL>
  <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
  <A HREF="./Code/auction/AuctionItem.java">AuctionItem.java</A></FONT>
  <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
  <A HREF="./Code/auction/AuctionItemHome.java">AuctionItemHome.java</A></FONT>
  <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
  <A HREF="./Code/auction/AuctionItemBean.java">AuctionItemBean.java</A></FONT>
  <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
  <A HREF="./Code/auction/AuctionItemPK.java">AuctionItemPk.java</A></FONT>
</UL>

<CODE>AuctionItem</CODE> is the remote interface. It describes
what the Bean does by declaring the developer-defined methods that 
provide the business logic for this Bean. These methods are the ones
used by the client to interact with the Bean over the remote connection.
Its name maps to the

⌨️ 快捷键说明

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