Weblogic中,JSP调用EJB问题 程序中JNDI对吗?有没有弄清EJB的各个接口都是使用Weblogic做服务器吗?上下文环境正确初始化了吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 回楼上的,已经初始化了, Properties props =new Properties(); props.setProperty("java.naming.factory.initial","weblogic.jndi.WLInitialContextFactory"); props.setProperty("java.naming.provider.url","t3://192.168.2.163:7001"); Context context = new InitialContext(props); 我写的一个简单的jsp调用ejb的。自己看看吧,希望对你有些帮助。 <%@ page contentType="text/html; charset=GB2312" %><%@ page import=" java.util.*; javax.ejb.*; javax.naming.*; javax.rmi.*; java.rmi.*; cmps.*;" %><html><head><title>jsp1</title></head><body bgcolor="#00b46e"><center> <% out.println("jsp调用ejb显示<br>"); try{ Properties properties=new Properties(); Context ctx; properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); ctx=new InitialContext(properties); properties.put(Context.PROVIDER_URL,"t3://localhost:7001"); Object hellojndi=ctx.lookup("UsertableRemote"); UsertableRemoteHome home=(UsertableRemoteHome)PortableRemoteObject.narrow(hellojndi,UsertableRemoteHome.class); // UsertableRemote hello=(Hello)PortableRemoteObject.narrow(home.create(),UsertableRemote.class); Collection allusers=home.findAll(); Iterator colIterator=allusers.iterator(); UsertableRemote yuan; while(colIterator.hasNext()){ yuan=(UsertableRemote)PortableRemoteObject.narrow(colIterator.next(),UsertableRemote.class); out.println("名字:"+yuan.getName()+" "+"密码:"+yuan.getPassword()); out.print("<br>"); } } catch(Exception ba){ out.println(ba.getMessage()); }%></center></body></html> 那是不是要将EJB包含的类放在Weblogic的applications\DefaultWebApp\WEB-INF\classes下面,这样的话,JSP才可以找到相应的类,进面访问EJB呢? 我觉得可能是由于这样的原因:weblogic对不同的模块使用不同的类装载器,所以彼此之间看不到相互的类文件.要想解决此问题,有三种方法:1,把你的EJB类文件放在一个jar文件中,然后将其放在APP-INF/lib下.(你知道ear文件的结构吧!)2,把jar文件放在应用程序的根目录下,假设包含你编写的EJB class文件的jar文件叫EJB.jar,编写一个文本文件(假设为text),写如下内容: Class-Path: EJB.jar 假设你的web应用程序的存档文件为:web.war,执行如下命令: jar umf text web.war 应该就行了.3,在应用程序的weblogic-application.xml里定义一个classloader结构:<classloader-structure> <module-ref> <module-uri>EJB.jar</module-uri> </module-ref> <classloader-structure> <module-ref> <module-uri>web.war</module-uri> </module-ref> </classloader-structure></classloader-structure> 关于如何打包J2EE Web应用,继续学习ing... Struts2通配符错误、{N}取不到中的值。 有谁知道如何用junit调试 struts2+spring 请教session问题 如何做可执行文件 freemarker中怎么使用自定义标签? 请详细点 想从事j2ee,请大家给个学习建议? 关于apacheDS的ldap问题,用JXplorer Struts的一些问题,急。。。 有关jndi的设置 帮忙啊!我写的第一个EJB程序,发布没有问题,客户端调用时错误! 有谁使用过Sun Application Server 7,可否帮小弟看一个如何配置JNDI的问题? Entity Bean的ejbActivate问题?
Properties props =new Properties();
props.setProperty("java.naming.factory.initial","weblogic.jndi.WLInitialContextFactory");
props.setProperty("java.naming.provider.url","t3://192.168.2.163:7001");
Context context = new InitialContext(props);
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import=" java.util.*;
javax.ejb.*;
javax.naming.*;
javax.rmi.*;
java.rmi.*;
cmps.*;"
%>
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor="#00b46e">
<center>
<%
out.println("jsp调用ejb显示<br>");
try{
Properties properties=new Properties();
Context ctx;
properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ctx=new InitialContext(properties);
properties.put(Context.PROVIDER_URL,"t3://localhost:7001");
Object hellojndi=ctx.lookup("UsertableRemote");
UsertableRemoteHome home=(UsertableRemoteHome)PortableRemoteObject.narrow(hellojndi,UsertableRemoteHome.class);
// UsertableRemote hello=(Hello)PortableRemoteObject.narrow(home.create(),UsertableRemote.class);
Collection allusers=home.findAll();
Iterator colIterator=allusers.iterator();
UsertableRemote yuan;
while(colIterator.hasNext()){
yuan=(UsertableRemote)PortableRemoteObject.narrow(colIterator.next(),UsertableRemote.class);
out.println("名字:"+yuan.getName()+" "+"密码:"+yuan.getPassword());
out.print("<br>");
}
}
catch(Exception ba){
out.println(ba.getMessage());
}
%>
</center>
</body>
</html>
Class-Path: EJB.jar
假设你的web应用程序的存档文件为:web.war,执行如下命令:
jar umf text web.war
应该就行了.3,在应用程序的weblogic-application.xml里定义一个classloader结构:
<classloader-structure>
<module-ref>
<module-uri>EJB.jar</module-uri>
</module-ref>
<classloader-structure>
<module-ref>
<module-uri>web.war</module-uri>
</module-ref>
</classloader-structure>
</classloader-structure>