能在jsp中直接调用EJB吗?

Yukon 2003-03-27 09:30:46
我知道可以用jsp调用javabean,然后用javabean来调用jar包,但能在jsp文件中直接调用eJB吗?
最好能给个例子,谢谢了
...全文
32 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
geyf 2003-03-27
  • 打赏
  • 举报
回复
当然可以,
<html>
<title>
ejb client
</title>
<%@ include file="import.jsp" %>
<body bgcolor="#FFFFCC">
</body>
<%
String JNDI_NAME = "statelessSession.TraderHome";

TraderHome home = null;
Trader trader = null;

try
{
out.println("Beginning statelessSession.Client...");
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
InitialContext ctx = new InitialContext(h);

home = (TraderHome)ctx.lookup(JNDI_NAME);
// trader = (Trader)PortableRemoteObject.narrow(home.create(), Trader.class);
trader = (Trader)home.create();
String [] stocks = {"BEAS", "MSFT", "AMZN", "HWP" };

// execute some buys
for (int i=0; i<stocks.length; i++) {
int shares = (i+1) * 100;
out.println("Buying "+shares+" shares of "+stocks[i]+".");
trader.buy(stocks[i], shares);
}

// execute some sells
for (int i=0; i<stocks.length; i++) {
int shares = (i+1) * 100;
out.println("Selling "+shares+" shares of "+stocks[i]+".");
trader.sell(stocks[i], shares);
}

}catch (Exception e) {
out.println(" error!Exception is " + e.getMessage());
}finally {
try {
// remove the Trader
if (trader!= null) {

out.println("Removing the trader");
trader.remove();
}
} catch (Exception e1) {
out.println("trader.remove() error:" + e1.getMessage());
}
}
%>
</html>
kofwr 2003-03-27
  • 打赏
  • 举报
回复
可以,通过JNDI就可以..
hanty 2003-03-27
  • 打赏
  • 举报
回复
可以的
按照正常调用的方式就可以调用
我在网络上可以看到过现成的例子,不过不记得在什么地方看到的了

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧