亚洲一区二区三区四区中文字幕,日本精品在线一区,亚洲综合精品http://www.aygfsteel.com/waynemao/zh-cnThu, 19 Jun 2025 10:20:07 GMTThu, 19 Jun 2025 10:20:07 GMT60JMS (2)http://www.aygfsteel.com/waynemao/archive/2008/09/14/228902.htmlwaynemaowaynemaoSun, 14 Sep 2008 08:40:00 GMThttp://www.aygfsteel.com/waynemao/archive/2008/09/14/228902.htmlhttp://www.aygfsteel.com/waynemao/comments/228902.htmlhttp://www.aygfsteel.com/waynemao/archive/2008/09/14/228902.html#Feedback0http://www.aygfsteel.com/waynemao/comments/commentRss/228902.htmlhttp://www.aygfsteel.com/waynemao/services/trackbacks/228902.html異步隊(duì)列消息的接收有一點(diǎn)區(qū)別,但發(fā)送的代碼不用改變:

 1@Stateless
 2public class JMSReceiveBean implements JMSReceiveRemote {
 3
 4    @Resource(name = "jms/Queue")
 5    private Queue queue;
 6    @Resource(name = "jms/ConnectionFactory")
 7    private ConnectionFactory queueFactory;
 8
 9    private void receiveJMSMessageFromQueue() throws Exception {
10        Connection connection = null;
11        Session session = null;
12        connection = queueFactory.createConnection();
13        session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
14        MessageConsumer consumer = session.createConsumer(queue);
15        consumer.setMessageListener(new MessageListener() {
16
17            public void onMessage(Message message) {
18                TextMessage msg = (TextMessage) message;
19                try {
20                    String txt = msg.getText();
21                    Logger.getLogger(JMSReceiveBean.class.getName()).log(Level.SEVERE, txt);
22                }
 catch (Exception ex) {
23                    ex.printStackTrace();
24                }

25            }

26        }
);
27        
28        connection.start();
29    }

30
31    public void receiveMessage() {
32        try {
33            receiveJMSMessageFromQueue();
34        }
 catch (Exception ex) {
35            Logger.getLogger(JMSReceiveBean.class.getName()).log(Level.SEVERE, null, ex);
36        }

37    }

38}

在15行消息使用者上設(shè)置了一個(gè)消息監(jiān)聽器,而沒有使用同步的receive方法。由于這是異步接收消息,程序并沒有處于阻塞狀態(tài),為了避免在接收到消息之前連接終止,所以在28行之后并沒有關(guān)閉Connection,實(shí)際上這一步是不可缺少的。

waynemao 2008-09-14 16:40 發(fā)表評論
]]>
JMS (1)http://www.aygfsteel.com/waynemao/archive/2008/09/14/228843.htmlwaynemaowaynemaoSat, 13 Sep 2008 21:31:00 GMThttp://www.aygfsteel.com/waynemao/archive/2008/09/14/228843.htmlhttp://www.aygfsteel.com/waynemao/comments/228843.htmlhttp://www.aygfsteel.com/waynemao/archive/2008/09/14/228843.html#Feedback0http://www.aygfsteel.com/waynemao/comments/commentRss/228843.htmlhttp://www.aygfsteel.com/waynemao/services/trackbacks/228843.html閱讀全文

waynemao 2008-09-14 05:31 發(fā)表評論
]]>
EJB3 (7)http://www.aygfsteel.com/waynemao/archive/2008/09/13/228705.htmlwaynemaowaynemaoSat, 13 Sep 2008 03:14:00 GMThttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228705.htmlhttp://www.aygfsteel.com/waynemao/comments/228705.htmlhttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228705.html#Feedback0http://www.aygfsteel.com/waynemao/comments/commentRss/228705.htmlhttp://www.aygfsteel.com/waynemao/services/trackbacks/228705.html有狀態(tài)會(huì)話bean的開發(fā),首先創(chuàng)建遠(yuǎn)程接口:

@Remote
public interface HelloRemote {

    String sayHi();

    
void init(String name);
    
    
void remove();
    
}

接著開發(fā)有狀態(tài)會(huì)話bean:
@Stateful
public class HelloBean implements HelloRemote {
    
private String name;
    
private Logger log = Logger.getLogger(this.getClass().getName());
    
    
public String sayHi() {
        
return "Hi " + name;
    }


    
public void init(String name) {
        
this.name = name;
    }

    
    @PostConstruct
    
public void postConstrut(){
        log.info(
"create " + this);
    }

    
    @PreDestroy
    
public void preDestory(){
        log.info(
"destory " + this);
    }

    
    @PostActivate
    
public void postActivate(){
        log.info(
"activate " + this);
    }

    
    @PrePassivate
    
public void prePassivate(){
        log.info(
"passivate " + this);
    }

    
    @Remove
    
public void remove(){
        log.info(
"remove " + this);
    }

}

@Stateful注釋表明這是一個(gè)有狀態(tài)會(huì)話bean,其他的注釋是管理會(huì)話bean的生命周期。@PostConstruct注釋表明方法將會(huì)在bean實(shí)例化并完成依賴注入后由容器調(diào)用此方法;@PreDestory注釋表示方法會(huì)在容器刪除bean實(shí)例前由容器調(diào)用;以上兩個(gè)注釋所有的EJB(包括MDB)都可以用。@PostActivate注釋表示容器在激活bean后調(diào)用此方法;@PrePassivate注釋表示容器在鈍化bean前調(diào)用此方法;以上兩個(gè)注釋是有狀態(tài)會(huì)話bean所特有。@Remove注釋也是有狀態(tài)會(huì)話bean所特有,也是用戶唯一可以能控制的生命周期方法,一旦用戶在客戶端調(diào)用此方法,容器將刪除bean實(shí)例。接著看客戶端的測試代碼:
<%
           InitialContext ctx 
= new InitialContext();
           HelloRemote helloBean 
= (HelloRemote)ctx.lookup(HelloRemote.class.getName());
           helloBean.init(
"Tom");
           out.println(helloBean.sayHi());
           helloBean.remove();
%>

很簡單,只是多調(diào)用了一個(gè)remove方法。

waynemao 2008-09-13 11:14 發(fā)表評論
]]>
EJB3 (6)http://www.aygfsteel.com/waynemao/archive/2008/09/13/228692.htmlwaynemaowaynemaoFri, 12 Sep 2008 20:36:00 GMThttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228692.htmlhttp://www.aygfsteel.com/waynemao/comments/228692.htmlhttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228692.html#Feedback0http://www.aygfsteel.com/waynemao/comments/commentRss/228692.htmlhttp://www.aygfsteel.com/waynemao/services/trackbacks/228692.htmlWeb服務(wù)客戶端可以通過bean的Web服務(wù)端點(diǎn)實(shí)現(xiàn)類來訪問無狀態(tài)會(huì)話Bean。在默認(rèn)情況下,bean類中的所有公共方法對于Web服務(wù)客戶端都是可訪問的。@WebMethod注釋可以自定義Web服務(wù)方法,一旦在公共方法上使用該注釋,那么其他沒使用@WebMethod注釋的方法將不會(huì)對Web服務(wù)客戶端展現(xiàn)。
首先新建一個(gè)EJB模塊,然后在EJB模塊上新建一個(gè)WebService,代碼如下:

@WebService()
@Stateless()
public class Dog {
    
    @WebMethod(operationName 
= "ganr")
    
public String ganr() {
        
return "Wo-Wo-Wo";
    }


}

Dog類同時(shí)使用了@WebService和@Stateless注釋,web服務(wù)端點(diǎn)只能是無狀態(tài)會(huì)話bean,web服務(wù)本身就是無狀態(tài)的。我們還用@WebMethod注釋向Web服務(wù)客戶端公開了一個(gè)ganr方法,完成后打包部署。
接著我們創(chuàng)建一個(gè)Web模塊,然后在Web項(xiàng)目上右鍵,選新建--Web服務(wù)客戶端,指定項(xiàng)目或者WSDL url。接著新建一個(gè)Servlet,然后右鍵調(diào)用Web服務(wù)操作,我們找到Dog服務(wù)的garn方法點(diǎn)確定,代碼自動(dòng)生成:
@WebServiceRef(wsdlLocation = "http://localhost:8080/DogService/Dog?wsdl")
    
private DogService service;

@WebServiceRef注釋聲明了一個(gè)到Web服務(wù)的引用
try // Call Web Service Operation

                ejb.Dog port 
= service.getDogPort();
                
// TODO process result here
                java.lang.String result = port.ganr();
                out.println(
"Result = " + result);
            }
 catch (Exception ex) {
                
// TODO handle custom exceptions here
            }

service.getDogPort()方法獲取到服務(wù)的一個(gè)代理,也稱為端口。接著看jsp:
  <%
    
try {
    ejb.DogService service 
= new ejb.DogService();
    ejb.Dog port 
= service.getDogPort();
    
// TODO process result here
    java.lang.String result = port.ganr();
    out.println(
"Result = "+result);
    }
 catch (Exception ex) {
    
// TODO handle custom exceptions here
    }

    
%>

發(fā)現(xiàn)只有一點(diǎn)點(diǎn)不同,完成后部署web應(yīng)用并運(yùn)行測試。

我們還可以通過一個(gè)現(xiàn)有的會(huì)話Bean創(chuàng)建Web服務(wù),還是拿HelloWorld舉例,首先創(chuàng)建一個(gè)遠(yuǎn)程接口:
@Remote
public interface HelloRemote {

    String sayHi(String name);
}

再創(chuàng)建一個(gè)無狀態(tài)會(huì)話bean,先已經(jīng)說過了,只能是無狀態(tài)會(huì)話bean:
@Stateless
public class HelloBean implements HelloRemote {

    
public String sayHi(String name) {
        
return "Hi " + name; 
    }

}

然后新建一個(gè)Web服務(wù)Hello,只不過在彈出窗口中要選中“通過現(xiàn)有會(huì)話bean創(chuàng)建Web服務(wù)”單選框,并瀏覽指定HelloBean,代碼自動(dòng)完成:
@WebService()
@Stateless()
public class Hello {
    @EJB
    
private HelloRemote ejbRef;
    
// Add business logic below. (Right-click in editor and choose
    
// "Web Service > Add Operation"

    @WebMethod(operationName 
= "sayHi")
    
public String sayHi(@WebParam(name = "name")String name) {
        
return ejbRef.sayHi(name);
    }

}

我們看到Hello服務(wù)里引用了一個(gè)HelloRemote接口,并發(fā)現(xiàn)遠(yuǎn)程接口公開的方法也被Hello服務(wù)公開,完成后打包部署EJB模塊。接著在Web服務(wù)客戶端測試,這和之前的步驟一樣,不再贅述,直接看代碼吧:
@WebServiceRef(wsdlLocation = "http://localhost:8080/HelloService/Hello?wsdl")
    
private HelloService service;

    
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            
throws ServletException, IOException {
        response.setContentType(
"text/html;charset=UTF-8");
        PrintWriter out 
= response.getWriter();
        
try {
            
try // Call Web Service Operation

                ejb.Hello port 
= service.getHelloPort();
                
// TODO initialize WS operation arguments here
                java.lang.String name = "Tom";
                
// TODO process result here
                java.lang.String result = port.sayHi(name);
                out.println(
"Result = " + result);
            }
 catch (Exception ex) {
                
// TODO handle custom exceptions here
            }

 

<%
    
try {
    ejb.HelloService service 
= new ejb.HelloService();
    ejb.Hello port 
= service.getHelloPort();
     
// TODO initialize WS operation arguments here
    java.lang.String name = "Tom";
    
// TODO process result here
    java.lang.String result = port.sayHi(name);
    out.println(
"Result = "+result);
    }
 catch (Exception ex) {
    
// TODO handle custom exceptions here
    }

    
%>

發(fā)現(xiàn)一個(gè)問題,一個(gè)應(yīng)用上不能新建兩個(gè)Web服務(wù)客戶端(Dog和Hello),只有一個(gè)能有效使用(只找到一份工件),這是為什么?

waynemao 2008-09-13 04:36 發(fā)表評論
]]>
WebService (1)http://www.aygfsteel.com/waynemao/archive/2008/09/13/228691.htmlwaynemaowaynemaoFri, 12 Sep 2008 18:31:00 GMThttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228691.htmlhttp://www.aygfsteel.com/waynemao/comments/228691.htmlhttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228691.html#Feedback0http://www.aygfsteel.com/waynemao/comments/commentRss/228691.htmlhttp://www.aygfsteel.com/waynemao/services/trackbacks/228691.html新建web項(xiàng)目,然后創(chuàng)建一個(gè)WEB服務(wù):

@WebService()
public class Hello {
    @WebMethod(operationName 
= "sayHi")
    
public String sayHi(@WebParam(name = "name")String name) {
       
return "Hi " + name;
    }

}


可以在源圖上右鍵,選Web服務(wù)--添加操作,也可以在設(shè)計(jì)圖上直接添加操作。@WebService標(biāo)注表明該類是一個(gè)web服務(wù),展現(xiàn)給web服務(wù)客戶端的業(yè)務(wù)方法必須使用@WebMethod標(biāo)注來表示。打包部署該web應(yīng)用,web服務(wù)自動(dòng)會(huì)發(fā)布。可以在glassfish應(yīng)用服務(wù)器上找到該web服務(wù),直接測試或者查看服務(wù)器生成的WSDL

<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3.1-hudson-417-SNAPSHOT. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3.1-hudson-417-SNAPSHOT. -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservice/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://webservice/" name="HelloService">
    
<types>
        
<xsd:schema>
            
<xsd:import namespace="http://webservice/" schemaLocation="http://localhost:8080/WebServiceApp/HelloService?xsd=1">
            
</xsd:import>
        
</xsd:schema>
    
</types>
    
<message name="sayHi">
        
<part name="parameters" element="tns:sayHi">
        
</part>
    
</message>
    
<message name="sayHiResponse">
        
<part name="parameters" element="tns:sayHiResponse">
        
</part>
    
</message>
    
<portType name="Hello">
        
<operation name="sayHi">
            
<input message="tns:sayHi">
            
</input>
            
<output message="tns:sayHiResponse">
            
</output>
        
</operation>
    
</portType>
    
<binding name="HelloPortBinding" type="tns:Hello">
        
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document">
        
</soap:binding>
        
<operation name="sayHi">
            
<soap:operation soapAction="">
            
</soap:operation>
            
<input>
                
<soap:body use="literal">
                
</soap:body>
            
</input>
            
<output>
                
<soap:body use="literal">
                
</soap:body>
            
</output>
        
</operation>
    
</binding>
    
<service name="HelloService">
        
<port name="HelloPort" binding="tns:HelloPortBinding">
            
<soap:address location="http://localhost:8080/WebServiceApp/HelloService">
            
</soap:address>
        
</port>
    
</service>
</definitions>


也可以編寫客戶端測試,新建一個(gè)普通的java項(xiàng)目,在項(xiàng)目上右鍵,選擇新建--Web服務(wù)客戶端,在彈出窗口中指定WebService項(xiàng)目或者WSDL url,點(diǎn)擊完成。在源代碼上右鍵,選擇Web服務(wù)客戶端資源--調(diào)用Web服務(wù)操作,在彈出窗口中選擇sayHi操作,點(diǎn)確定,測試代碼自動(dòng)生成:

public class Main {

    
public static void main(String[] args) {

        
try 

            webservice.HelloService service 
= new webservice.HelloService();
            webservice.Hello port 
= service.getHelloPort();
            
            java.lang.String name 
= "Tom";
            java.lang.String result 
= port.sayHi(name);
            System.out.println(
"Result = " + result);
        }
 catch (Exception ex) {
            
// TODO handle custom exceptions here
        }

    }

}

運(yùn)行該客戶端,結(jié)果將會(huì)輸出

waynemao 2008-09-13 02:31 發(fā)表評論
]]>
oracle視頻http://www.aygfsteel.com/waynemao/archive/2008/09/13/228688.htmlwaynemaowaynemaoFri, 12 Sep 2008 17:01:00 GMThttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228688.htmlhttp://www.aygfsteel.com/waynemao/comments/228688.htmlhttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228688.html#Feedback0http://www.aygfsteel.com/waynemao/comments/commentRss/228688.htmlhttp://www.aygfsteel.com/waynemao/services/trackbacks/228688.htmloracle10g_1

oracle10g_2

oracle10g_3_1

oracle10g_3_2

oracle10g_4_1

oracle10g_4_2

oracle10g_5_1

oracle10g_5_2

oracle10g_6

oracle10g_7_1

oracle10g_7_2

oracle10g_8

oracle10g_9

oracle10g_10

oracle10g_11

oracle10g_12

oracle10g_13

oracle10g_14



waynemao 2008-09-13 01:01 發(fā)表評論
]]>
EJB3 (5)http://www.aygfsteel.com/waynemao/archive/2008/09/13/228685.htmlwaynemaowaynemaoFri, 12 Sep 2008 16:42:00 GMThttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228685.htmlhttp://www.aygfsteel.com/waynemao/comments/228685.htmlhttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228685.html#Feedback0http://www.aygfsteel.com/waynemao/comments/commentRss/228685.htmlhttp://www.aygfsteel.com/waynemao/services/trackbacks/228685.html同一個(gè)會(huì)話bean也可以實(shí)現(xiàn)多個(gè)遠(yuǎn)程接口,不過代碼上有些地方要注意,首先寫第一個(gè)接口:

@Remote
public interface HelloRemote {

    String sayHi(String name);
}

第二個(gè)接口:
@Remote
public interface HelloRemote1 {
    
    String sayBye(String name);
}

接下來寫會(huì)話bean,同時(shí)實(shí)現(xiàn)以上兩個(gè)接口:
@Stateless(mappedName="hello")
public class HelloBean implements HelloRemote, HelloRemote1 {

    
public String sayHi(String name) {
        
return "Hi " + name; 
    }


    
public String sayBye(String name) {
        
return "Bye " + name;
    }
    
}

注意這里用到了mappedName元素,這個(gè)很關(guān)鍵。把EJB模塊打包部署,接下來在遠(yuǎn)程客戶端測試,先寫Servlet:
    @EJB(mappedName="hello#ejb.HelloRemote1")
    
private HelloRemote1 helloBean1;
    @EJB(mappedName
="hello#ejb.HelloRemote")
    
private HelloRemote helloBean;

注意@EJB標(biāo)注里也使用了mappedName元素,值的樣式是:JNDI名#包名.接口名。再看Jsp:
<%
            InitialContext ctx 
= new InitialContext();
            HelloRemote helloBean 
= (HelloRemote)ctx.lookup("hello#ejb.HelloRemote");
            out.println(helloBean.sayHi(
"Tom"));
            HelloRemote1 helloBean1 
= (HelloRemote1)ctx.lookup("hello#ejb.HelloRemote1");
            out.println(
"<br>" + helloBean1.sayBye("Tom"));
%>

和Servlet中的一樣

waynemao 2008-09-13 00:42 發(fā)表評論
]]>
EJB3 (4)http://www.aygfsteel.com/waynemao/archive/2008/09/13/228680.htmlwaynemaowaynemaoFri, 12 Sep 2008 16:21:00 GMThttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228680.htmlhttp://www.aygfsteel.com/waynemao/comments/228680.htmlhttp://www.aygfsteel.com/waynemao/archive/2008/09/13/228680.html#Feedback0http://www.aygfsteel.com/waynemao/comments/commentRss/228680.htmlhttp://www.aygfsteel.com/waynemao/services/trackbacks/228680.html如果一個(gè)遠(yuǎn)程接口有兩個(gè)實(shí)現(xiàn),需要用mappedName來區(qū)分
首先定義一個(gè)遠(yuǎn)程接口:

@Remote
public interface HelloRemote {

    String sayHi(String name);
}


第一個(gè)實(shí)現(xiàn):
@Stateless(mappedName="hello")
public class HelloBean implements HelloRemote {

    
public String sayHi(String name) {
        
return "Hi " + name; 
    }

}

第二個(gè)實(shí)現(xiàn):
@Stateless(mappedName="hello2")
public class HelloBean2 implements HelloRemote{

    
public String sayHi(String name) {
        
return "Hello " + name;
    }


}

兩個(gè)無狀態(tài)會(huì)話bean實(shí)現(xiàn)了同一個(gè)遠(yuǎn)程接口,但它們的mappedName不一樣,還有它們各自重寫了sayHi業(yè)務(wù)方法。部署EJB模塊然后測試,首先是Servlet:
    @EJB(mappedName="hello2")
    
private HelloRemote helloBean2;
    @EJB(mappedName
="hello")
    
private HelloRemote helloBean;

然后是JSP:
<%
            InitialContext ctx 
= new InitialContext();
            HelloRemote helloBean 
= (HelloRemote)ctx.lookup("hello");
            out.println(helloBean.sayHi(
"Tom"));
            HelloRemote helloBean2 
= (HelloRemote)ctx.lookup("hello2");
            out.println(
"<br>" + helloBean2.sayHi("Tom"));
%>

呵呵,遠(yuǎn)程調(diào)用也實(shí)現(xiàn)了多態(tài)

waynemao 2008-09-13 00:21 發(fā)表評論
]]>
EJB3 (3)http://www.aygfsteel.com/waynemao/archive/2008/09/12/228669.htmlwaynemaowaynemaoFri, 12 Sep 2008 14:24:00 GMThttp://www.aygfsteel.com/waynemao/archive/2008/09/12/228669.htmlhttp://www.aygfsteel.com/waynemao/comments/228669.htmlhttp://www.aygfsteel.com/waynemao/archive/2008/09/12/228669.html#Feedback0http://www.aygfsteel.com/waynemao/comments/commentRss/228669.htmlhttp://www.aygfsteel.com/waynemao/services/trackbacks/228669.html
@Local
public interface MessageLocal {

    String getMessage();
    
}

接著編寫一個(gè)會(huì)話bean實(shí)現(xiàn)該接口:
@Stateless
public class MessageBean implements MessageLocal {

    
public String getMessage() {
        
return "Hello world";
    }

    
}

然后創(chuàng)建一個(gè)遠(yuǎn)程接口:

@Remote
public interface HelloRemote {

    String welcome();
    
}

編寫一個(gè)會(huì)話bean實(shí)現(xiàn)該接口:
@Stateless
public class HelloBean implements HelloRemote {
    @EJB
    
private MessageLocal messageBean;

    
public String welcome() {
        
return messageBean.getMessage();
    }

    
}

在遠(yuǎn)程對象里聲明了一個(gè)本地接口的引用,并嘗試在遠(yuǎn)程方法當(dāng)中調(diào)用本地接口的本地方法。這些都沒問題,打包部署成功。
<%
            InitialContext ctx 
= new InitialContext();
            HelloRemote helloBean 
= (HelloRemote)ctx.lookup(HelloRemote.class.getName());
            out.println(helloBean.welcome());
%>

在遠(yuǎn)程客戶端的代碼如此,看起來一切正常,不過在部署WEB模塊的時(shí)候報(bào)異常:正在域中部署應(yīng)用程序 失敗;為模塊 [EjbWebClient] 裝入部署描述符時(shí)出錯(cuò) -- Cannot resolve reference Unresolved Ejb-Ref ejb.HelloBean/messageBean@jndi: @null@ejb.MessageLocal@Session@null


waynemao 2008-09-12 22:24 發(fā)表評論
]]>
EJB3 (2)http://www.aygfsteel.com/waynemao/archive/2008/09/12/228658.htmlwaynemaowaynemaoFri, 12 Sep 2008 13:29:00 GMThttp://www.aygfsteel.com/waynemao/archive/2008/09/12/228658.htmlhttp://www.aygfsteel.com/waynemao/comments/228658.htmlhttp://www.aygfsteel.com/waynemao/archive/2008/09/12/228658.html#Feedback0http://www.aygfsteel.com/waynemao/comments/commentRss/228658.htmlhttp://www.aygfsteel.com/waynemao/services/trackbacks/228658.html一個(gè)會(huì)話bean即可以遠(yuǎn)程訪問,也可以本地訪問,盡管這種現(xiàn)象不常見。
我們先定義遠(yuǎn)程接口:

@Remote
public interface HelloRemote {

    String sayHi(String name);

    String sayByeBye(String name);
    
}

接著定義本地接口:
@Local
public interface HelloLocal {

    String sayBye(String name);
    
}

然后編寫一個(gè)會(huì)話bean同時(shí)實(shí)現(xiàn)兩個(gè)接口:
@Stateless
public class HelloBean implements HelloRemote, HelloLocal {

    
public String sayHi(String name) {
        
return "Hi " + name;
    }

    
    
public String sayBye(String name) {
        
return "Bye " + name;
    }

    
    
public String sayByeBye(String name) {
        
return sayBye(name);
    }

    
}

那么,這還是一個(gè)無狀態(tài)會(huì)話bean,不過即可以遠(yuǎn)程訪問,也可以本地訪問。
<%
            InitialContext ctx 
= new InitialContext();
            HelloRemote helloBean 
= (HelloRemote)ctx.lookup(HelloRemote.class.getName());
            out.println(helloBean.sayHi(
"Tom"));
            out.println(
"<br>" + helloBean.sayByeBye("Tom"));
%>

遠(yuǎn)程訪問只能獲得遠(yuǎn)程接口的代理,然后調(diào)用遠(yuǎn)程業(yè)務(wù)方法。在遠(yuǎn)程客戶端是無法獲得本地接口的引用,更別說訪問本地方法了。

waynemao 2008-09-12 21:29 發(fā)表評論
]]>
主站蜘蛛池模板: 临桂县| 大名县| 获嘉县| 兴隆县| 嘉峪关市| 天峻县| 米脂县| 株洲县| 通海县| 澄江县| 新疆| 桂平市| 原平市| 钦州市| 南澳县| 泽库县| 沐川县| 鲜城| 安仁县| 即墨市| 庆元县| 镇江市| 汪清县| 清徐县| 巴林右旗| 竹北市| 元谋县| 武鸣县| 大庆市| 略阳县| 安阳县| 新平| 诸暨市| 会东县| 阿尔山市| 沐川县| 织金县| 托里县| 涡阳县| 建宁县| 繁昌县|