我已经知道了。假如你的EJB为A,你将A.class,AHome.class放到你的webApplication的WEB-INF/classes下面就行了。注意包名的问题。要不然就会出现转型错误。你小心我告你盗版啊。
哈哈……
哈哈……
解决方案 »
- java操作List集合问题?
- 找个Java程序
- Spring2.0+Hibernate3.3.2事务配置问题
- 求助下,用httpxml发消息,直接写个main函数测试可以发送,用程序触发就有问题
- 急~~~需要一个经典的OA和EJB实例系统 并附有教程及源码 最好能帮我详细解释下!!!
- 求用jsp做一个手机号码抽奖的程序!急急!在线等!
- 网络项目合作开发团队成员招募中...
- 如何在servlet中获取请求的url?
- ok,我知道错了,现在请教前辈们,如何调用ejb的local接口?
- 请问各位高手,JAVA中开发网络应用程序所要的服务器端的JSDK要哪里去下载!!!!!!!!
- 怎么设置发布多个webservice到同一个端口?
- 这个问题是SQL Server驱动的问题吗???
可错误依然,
我盗版你,却盗版不了你的成功!
唉~~~~~~~~
我在测试项目上新建web和servlet,复制了aa的src下的remote.java和home.java,
到bb的src下,并把remote.java的package aa改做package bb,然后编绎成.war,并布暑成功!
然后运行servlet就出现了上面的问题!
后来我又把aa下的remote.class和home.class拷到bb下的class,还是不行!
还是有上面问题!
start...lookup OKError narrow:Cannot narrow remote object to qq.bean1Homecreate:null Error in HelloWorld(): Remote interface reference is null. It must be created by calling one of the Home interface methods first. Calling HelloWorld() null ambest(许愿) :我servlet程序和你一样的!(在上面)
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
/**
* <p>Title: ambest</p>
* <p>Description: EJBtest</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: AMB</p>
* @author ambest
* @version 1.0
*/public class Servlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";
private static final int MAX_OUTPUT_LINE_LENGTH = 100;
private boolean logging = true;
private bean1Home h= null;
private bean1 b= null;
PrintWriter out; private Context getInitialContext() throws Exception {
String url = "t3://hzh:7003";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
} return new InitialContext(properties);
}
catch(Exception e) {
out.println("Unable to connect to WebLogic server at " + url);
out.println("Please make sure that the server is running.");
throw e;
}
} //Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
out = response.getWriter();
out.println("<html>");
out.println("<head><title>ServletEJBTest</title></head>");
out.println("<body>"); long startTime = 0;
try {
//get naming context
Context context = getInitialContext();
out.println("<br/>start...<br/>");//调试时的输出信息。
//look up jndi name
Object ref = context.lookup("bean1");
out.println("lookup OK<br/>");
//look up jndi name and cast to Home interface
//sessionBean1Home = (SessionBean1Home)ref;
h=(bean1Home)PortableRemoteObject.narrow(ref,bean1Home.class);
//这两种方法是同样的问题。
//错误码应该是在这一行出的问题吧。
if (logging) {
long endTime = System.currentTimeMillis();
out.println("Succeeded initializing bean access through Home interface.");
out.println("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
out.println("<font color=red>Error narrow:"+e.getMessage()+"</font><br/>");
}
//create();
try {
b =h.create();
out.println("create ok");
if (logging) {
long endTime = System.currentTimeMillis();
out.println("Succeeded: create()");
out.println("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
out.println("create:"+e.getMessage());
} if (b== null) {
out.println("Error in HelloWorld(): " + ERROR_NULL_REMOTE);
}
out.println("Calling HelloWorld()");
startTime = System.currentTimeMillis(); try {
out.println("Hello World:"+b.helloworld("ddd"));
if (logging) {
long endTime = System.currentTimeMillis();
out.println("Succeeded: HelloWorld()");
out.println("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
out.println(e.getMessage());
} //out.println("<p>The servlet has received a " + request.getMethod() + ". This is the reply.</p>");
out.println("</body></html>");
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}