你可以在config.xml文件中配置好你的EJB,应该Sample里有的,然后再JSP里就可以使用了,EJB的优点不就在于分布式应用,不需要靠过来的!
解决方案 »
- spring结合mybatis多数据源
- dom4j获得子节点及节点值,急!!!
- 奇怪的问题!!!我没分析出来哪错了!!
- java连接informix数据库 老报错~是什么问题呀?
- Linux下的mysql问题
- 请问如果在HP上安装JDK1.4
- sos求助:望各位给点web service方面的资料(回帖有分)
- struts的问题!在线等待,解决了就给分!
- 关于毕业论文的开题,诚恳发言另外开贴给分
- 有关JDK的问题
- 各位大侠,在windows2000下用jb7调试RMI,用jb7提供的例子都通不过!!求救
- 我的xml文件生成的jtree是通过TreeModel生成的结构,我想问一下如何把它转为DefaultTreeModel?谢谢
不需要加在CLASSPATH里,部署后直接在JSP里import这个EJB包就可以了
在其他机器上调用一个EJB,只要知道EJB机器的IP和JNDI名就可以了。
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, "t3://ip:7001");
Context ctx = new InitialContext(properties);
Object ref = ctx.lookup("CmpBeanRemote");//HOME接口JNDI名
cmpRemoteHome = (CmpRemoteHome) PortableRemoteObject.narrow(ref, CmpRemoteHome.class);//得到HOME接口
config.xml里面指的是这个吗?
<Application Deployed="true" Name="hello" Path=".\config\mydomain\applications">
<EJBComponent Name="hello" Targets="myserver" URI="hello.jar"/>
</Application>我用console配置的hello.jar这个ejb包然后我的程序是这么写的:
<%@ page contentType = "text/html;charset=gb2312" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="javax.rmi.PortableRemoteObject"%>
<%@ page import="hello.*"%>
<html>
<head>
<title>调用ejb</title>
</head>
<body>
<%
Context ctx = new InitialContext();
Object h = ctx.lookup("HelloWorld");
HelloWorldHome home=(HelloWorldHome) PortableRemoteObject.narrow(h,HelloWorldHome.class);
HelloWorld hw = home.create();
out.println("this is a sample of ejb<br>");
String hello = hw.getString();
out.println("My EJB said:" +hello);
%>
</body>
</html>
编译提示第5行就错了
package hello does not exist
probably occurred due to an error in /jsp-ejb.jsp line 5:
<%@ page import="hello.*"%>我这边怎么就不能直接import呢?
set classpath 里面加上那个hello.jar,是可以的
现在的问题就是,如果让客户端的东东能够import 这个包在不拷贝到本地的情况下
拿位给我讲详细一点
你想想,如果你在本地没有这个类,你又如何能造型出这个类呢?
所以本地必须有hello.jar,其实也不需要hello.jar中的所有的类,
但至少要一个home接口和一个remote接口。
一般常用的做法都是写一个Bean来封装Session EJB, 写视图类来包装Entity bean。
另外,你一定要这样做的话,那么可以告诉你的是:
普通类调同一个服务器的已经发布了EJB类,无需加在classpath.但是调用其他服务器的,则必须加。而且,EJB要调用的类也必须加在classpath,是不是很麻烦。所以,良好的开发体系很重要。