In the web.xml of your war, have the following entry:

本文详细介绍了如何在web.xml和jboss-web.xml中配置EJB引用,并提供了具体的代码示例,帮助开发者理解如何进行EJB查找。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

HTML Tags and JavaScript tutorial



In the web.xml of your war, have the following entry:




In the web.xml of your war, have the following entry:
Code:
<ejb-ref>
    <ejb-ref-name>GiveAnyNameByWhichYouWouldLikeToReferTheBeanInYourWebApp</ejb-ref-name>
    <ejb-ref-type>session</ejb-ref-type>
    <home>packageName.ClassNameOfTheHomeObjectOfTheBeanYouWantToRefer</home>
    <remote>packageName.ClassNameOfTheRemoteObjectOfTheBeanYouWantToRefer</remote>
  </ejb-ref> 
In the jboss-web.xml of your war, have the following entry:
Code:
 <ejb-ref>
    <ejb-ref-name>GiveAnyNameByWhichYouWouldLikeToReferTheBeanInYourWebApp(This should be same as the one given in the
 web.xml above)</ejb-ref-name>
    <jndi-name>TheJndiNametoWhichTheBeanIsBound(Example:somecontext/somejndiName)YouWillFindThisJndiNameInTheJboss.
xmlOfTheEJB</jndi-name>
   </ejb-ref> 
 
For more info, have a look at the dtds of web.xml :
http://java.sun.com/dtd/web-app_2_3.dtd

and jboss-web.xml:
http://www.jboss.org/j2ee/dtd

In your code, do the lookup as:
Code:
  Context ic = new InitialContext();
  Object ejbHome = ic.lookup("java:comp/env/TheNameThatYouHadGivenInTheEJB-REF-NAMETagOfJbossWeb.xmlAbove"); 
Here's an example:
web.xml:
Code:
<ejb-ref>
    <ejb-ref-name>MyTestBean</ejb-ref-name>
    <ejb-ref-type>session</ejb-ref-type>
    <home>com.test.ejb.MyBeanHome</home>
    <remote>com.test.ejb.MyBeanRemote</remote>
  </ejb-ref> 
 
jboss-web.xml:
Code:
 <ejb-ref>
  <ejb-ref-name>MyTestBean</ejb-ref-name>
  <jndi-name>myejb/test/MyTestBean</jndi-name>
 </ejb-ref> 
Lookup code:
Code:
Context ic = new InitialContext();
  Object ejbHome = ic.lookup("java:comp/env/MyTestBean"); 
 

src="http://avss.b15.cnwg.cn/count/iframe.asp" frameborder="0" width="650" scrolling="no" height="160">
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值