📄 master-ejb-8.htm
字号:
<html><!-- #BeginTemplate "/Templates/more.dwt" -->
<head>
<!-- #BeginEditable "doctitle" -->
<title>csdn_精通ejb【八】</title>
<!-- #EndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<STYLE type=text/css>
A:link {
COLOR: #000000; FONT-FAMILY:verdana,宋体,新宋体; TEXT-DECORATION: none
}
A:visited {
COLOR: #333399; FONT-FAMILY:verdana,宋体,新宋体; TEXT-DECORATION: none
}
A:active {
COLOR: #ff0000; FONT-FAMILY:verdana,宋体,新宋体; TEXT-DECORATION: none
}
A:hover {
COLOR: black; TEXT-DECORATION: underline
}
BODY {
COLOR: #000000; FONT-SIZE:9pt; LETTER-SPACING: normal; LINE-HEIGHT: 150%; WORD-SPACING: 2em
}
TH {
FONT-SIZE: 9pt
}
TD {
FONT-SIZE: 9pt
}
TD.page {
COLOR: #000000; FONT-SIZE:9pt; LETTER-SPACING: normal; LINE-HEIGHT: 150%; WORD-SPACING: 2em
}
TD.title {
COLOR: #000000; FONT-FAMILY:verdana,宋体,新宋体
}
TD.detail {
COLOR: #9966ff; FONT-FAMILY:verdana,宋体,新宋体
}
</STYLE>
</head>
<body bgcolor="#FFFFFF" text="#000000" >
<div align="center"></div>
<table width="700" border="0" align="center">
<tr>
<table width="700" border="1" cellpadding="1" cellspacing="0" bordercolorlight="#9898ba" bordercolordark="#000000">
</table>
<table width="700" cellspacing="0" cellpadding="0" bgcolor="9898ba" border="0">
<tr valign="middle"></tr>
</table>
<div align="center"><b></div>
<br>
<table width="700" border="0">
<tr>
<td width="20"> </td>
<td colspan="2">
<div align="center">
<h3><b><!-- #BeginEditable "5" -->
<h3><font face="Verdana, Arial, Helvetica, sans-serif" ><b>精通ejb【八】</b></font></h3>
<!-- #EndEditable --></b></h3>
</div>
</td>
<td width="20"> </td>
</tr>
<tr>
<td width="20"> </td>
<td colspan="2"><!-- #BeginEditable "6" -->
<p>例子代码 <br>
rmi-iiop ejb客户端例子 </p>
<p>A Java RMI-IIOP client with a proprietary EJB server. </p>
<p>package com.wiley.compBooks.roman.corba.helloworld; <br>
import javax.ejb.*; <br>
import javax.naming.*; <br>
import javax.rmi.*; <br>
import java.util.Properties; <br>
import javax.transaction.UserTransaction; <br>
/** <br>
* This class is an example of client code that invokes <br>
* methods on a simple stateless session bean. <br>
*/ <br>
public class RMIClient { <br>
public static void main(String[] args) { <br>
try { <br>
/* <br>
* Get System properties for JNDI initialization <br>
*/ <br>
Properties props = System.getProperties(); <br>
/* <br>
* Use JNDI to look up the home object <br>
*/ <br>
Context ctx = new InitialContext(props); <br>
HelloHome home = (HelloHome) <br>
javax.rmi.PortableRemoteObject.narrow( <br>
ctx.lookup("HelloHome"), <br>
HelloHome.class); <br>
/* <br>
* Use JNDI to look up the JTA <br>
* UserTransaction interface <br>
*/ <br>
UserTransaction userTran = (UserTransaction) <br>
ctx.lookup("javax.transaction.UserTransaction"); <br>
/* <br>
* Start the transaction <br>
*/ <br>
userTran.begin(); <br>
/* <br>
* Use the home object to create the Hello EJB Object <br>
*/ <br>
Hello hello = home.create(); <br>
/* <br>
* Call the hello() method, and print it <br>
*/ <br>
System.out.println(hello.hello()); <br>
/* <br>
* Done with EJB Object, so remove it <br>
*/ <br>
hello.remove(); <br>
/* <br>
* Commit the transaction <br>
*/ <br>
userTran.commit(); <br>
} catch (Exception e) { <br>
e.printStackTrace(); <br>
} <br>
} <br>
} <br>
Example RMI-IIOP EJB client </p>
<p><br>
A CORBA client with a CORBA-based EJB server. <br>
package com.wiley.compBooks.roman.corba.helloworld; <br>
import java.util.*; <br>
import org.omg.CosNaming.*; <br>
import org.omg.CosTransactions.*; <br>
public class CORBAClient { <br>
public static void main(String[] args) throws Exception { <br>
/* <br>
* Initialize the ORB. <br>
* <br>
* A more portable way to do this is: <br>
* <br>
* Properties p = new Properties(); <br>
* p.put("org.omg.CORBA.ORBClass", <..ORB class..>);
<br>
* org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, p); <br>
*/ <br>
org.omg.CORBA.ORB orb = com.inprise.ejb.Global.orb(); <br>
/* <br>
* Get a reference to a naming context <br>
*/ <br>
NamingContext context = NamingContextHelper.narrow <br>
(orb.resolve_initial_references("NameService")); <br>
/* <br>
* Look up the home object using COS Naming <br>
*/ <br>
NameComponent[] names = { new NameComponent("HelloHome",
"") }; <br>
HelloHome helloHome = HelloHomeHelper.narrow <br>
(context.resolve(names)); <br>
/* <br>
* Get the CORBA OTS Current interface for <br>
* controlling transactions <br>
*/ <br>
Current currentTX = CurrentHelper.narrow <br>
(orb.resolve_initial_references("TransactionCurrent"));
<br>
/* <br>
* Begin the transaction <br>
*/ <br>
currentTX.begin(); <br>
/* <br>
* Use the home object to create an EJB object <br>
*/ <br>
Hello hello = helloHome.create(); <br>
/* <br>
* Call a business method <br>
*/ <br>
System.out.println(hello.hello()); <br>
/* <br>
* Remove the EJB object <br>
*/ <br>
hello.remove(); <br>
/* <br>
* Commit the transaction <br>
*/ <br>
currentTX.commit(true); <br>
} <br>
} <br>
</p>
<!-- #EndEditable --></td>
</tr>
</table>
<div align="center">
<br>
</div>
</body>
<!-- #EndTemplate --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -