?? 0075.htm
字號:
<html>
<head>
<title>新時代軟件教程:操作系統(tǒng) 主頁制作 服務(wù)器 設(shè)計軟件 網(wǎng)絡(luò)技術(shù) 編程語言 文字編輯</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
<!--
body, table {font-size: 9pt; font-family: 宋體}
a {text-decoration:none}
a:hover {color: red;text-decoration:underline}
.1 {background-color: rgb(245,245,245)}
-->
</style>
</head>
<p align="center"><script src="../../1.js"></script></a>
<p align="center"><big><strong>jsp與ejb通信</strong></big></p>
<div align="right">(編譯/Blueski)</div>
<br>
以下是一個snippet代碼,演示了JSP頁面如何與 EJB session bean進行相互作用。<br>
<br>
<%@ page import="javax.naming.*, javax.rmi.PortableRemoteObject,<br>
foo.AccountHome, foo.Account" %><br>
<%! <br>
//declare a "global" reference to an instance of the home interface of the session bean<br>
AccountHome accHome=null;<br>
<br>
public void jspInit() { <br>
//obtain an instance of the home interface<br>
InitialContext cntxt = new InitialContext( );<br>
Object ref= cntxt.lookup("java:comp/env/ejb/AccountEJB");<br>
accHome = (AccountHome)PortableRemoteObject.narrow(ref,AccountHome.class);<br>
}<br>
%><br>
<%<br>
//instantiate the session bean<br>
Account acct = accHome.create();<br>
//invoke the remote methods<br>
acct.doWhatever(...);<br>
// etc etc...<br>
%><br>
在JSP中java代碼應(yīng)該越少越好。<br>
在以上例子中,JSP設(shè)計者不得不處理和理解存取EJB的機理。 代替 在一個Mediator中對EJB機制的壓縮以及將EJB方法作為Mediator的方法,<br>
可以在jsp中使用 Mediator。Mediator通常由EJB設(shè)計者編寫。Mediator可以提供附加的值如attribute caching等.<br>
<br>
*****<br>
<br>
JSP scriptlet代碼必須最小化。如果要在jsp中直接請求ejb可能要在jsp 中寫許多代碼,包括try...catch等函數(shù)塊來進行操作。 <br>
<br>
使用一個標準的JavaBean作為一個jsp和EJB服務(wù)器的中介可以減少在jsp中的java代碼的數(shù)量,并可提高可重用性。這個JavaBean必須是一個你所存取的EJB的覆蓋(wrapper)。<br>
<br>
如果你使用標準的JavaBean,你可以使用 jsp:useBean標記來初始化EJB參數(shù),如服務(wù)器URL和服務(wù)器<br>
安全參數(shù)等。 <br>
<br>
自定義標記也可以是一種選擇。但是,這要求比一個簡單JavaBean wrapper更多的編碼。<br>
該處必須被重新寫為盡可能小的代碼并保證JSP腳本內(nèi)容盡可能輕(light)。<br>
</table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -