========= 客户访问程序 ===========
package j2eetest.zxadvice;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;public class ZxadviceServlet extends HttpServlet {
private Context ctx = null;
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String str = "初始值";
try{
ctx = new InitialContext();
Object h = ctx.lookup("ZxadviceSession");
ZxadviceSessionHome home = (ZxadviceSessionHome)javax.rmi.PortableRemoteObject.narrow(h , ZxadviceSessionHome.class);
ZxadviceSession hw = home.create();
str ="from EJB : " + hw.getContent("abian");
}catch(Exception e){
e.printStackTrace();
}
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>ZxadviceServlet</title></head>");
out.println("<body>");
out.println("<p> " + str + "</p>");
out.println("</body></html>");
} private Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
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) {
log("Unable to connect to WebLogic server at " + url);
log("Please make sure that the server is running.");
throw e;
}
}
//Clean up resources
public void destroy() {
}
}
package j2eetest.zxadvice;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;public class ZxadviceServlet extends HttpServlet {
private Context ctx = null;
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String str = "初始值";
try{
ctx = new InitialContext();
Object h = ctx.lookup("ZxadviceSession");
ZxadviceSessionHome home = (ZxadviceSessionHome)javax.rmi.PortableRemoteObject.narrow(h , ZxadviceSessionHome.class);
ZxadviceSession hw = home.create();
str ="from EJB : " + hw.getContent("abian");
}catch(Exception e){
e.printStackTrace();
}
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>ZxadviceServlet</title></head>");
out.println("<body>");
out.println("<p> " + str + "</p>");
out.println("</body></html>");
} private Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
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) {
log("Unable to connect to WebLogic server at " + url);
log("Please make sure that the server is running.");
throw e;
}
}
//Clean up resources
public void destroy() {
}
}
解决方案 »
- 求助:我们公司是本地公网运营商,想做光缆资源管理系统
- javamail的问题,在发送邮件时报错,报错,请帮我看看这个方法哪里错
- 关于web service的一个问题!
- dom4j 怎么控制 element.add(node)的插入位置?
- Javascript问题,提示缺少对象?急!
- 求一个正则表达式在线等
- 对已应用之间的调用,如何选择rpc还是mq?
- 请问:怎么获得jsp服务器(tomcat)发布的目录
- 在weblogic8.1上,struts jsp代码中标签bean:define无效。
- 我的jdk中为什么没有org.omg.CORBA.BOA;
- 求教,怎能从命令行手动生成weblogic7的描述符
- 刚做好的编程技术文章系统,欢迎来翻阅(Java)技术文章.
是本地的。
一般是通过一个SessionBean来包裹本地的实体Bean,client只能访问SessionBean,建议看看Facade模式。
我并没有把CMP(Local)的引用传给Client,是在SessionBean里面引用的上面代码显示:
---------- SessionBean -------------
private ZxadviceHome getHome() throws Exception {
Context ic = new InitialContext();
Object ref = ic.lookup("Zxadvice");
System.out.println("obj = "+ref);
ZxadviceHome imh = (ZxadviceHome)PortableRemoteObject.narrow(ref , ZxadviceHome.class);
return imh;
}
------------- over -----------------
javax.ejb.EJBException: Attempt to pass a reference to an EJBLocalObject to a remote client. A local EJB component may only be accessed by clients co-located in the same ear or standalone jar file. <<no stack trace available>>
多谢各位!!