专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > JBoss

【】关于Tomcat中Web客户端,连接JBOSS中EJB3服务端出现的有关问题

发布时间:2010-06-14 17:12:35 文章来源:www.iduyao.cn 采编人员:星星草
【求救】关于Tomcat中Web客户端,连接JBOSS中EJB3服务端出现的问题
服务端(test):
HelloWorld接口:
Java code
package com.test.ejb3;

public interface HelloWorld {
    public String SayHello(String name);
}


HelloWorldBean接口实现类:
Java code
package com.test.ejb3.impl;

import com.test.ejb3.HelloWorld;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless
@Remote (HelloWorld.class)
@Local (HelloWorld.class)
public class HelloWorldBean implements HelloWorld {

    public String SayHello(String name) {
        return name+":Hello~~!";
    }

}





客户端(web):
EJBFactory你懂的:
Java code
package com.web.util;

import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;

public class EJBFactory {

    public static Object getEJB(String jndipath) {
        try {
            Properties props = new Properties();
            props.setProperty("javax.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); 
            props.setProperty("javax.naming.provider.url", "jnp://127.0.0.1:1099"); 
            props.setProperty("javax.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); 
            props.setProperty("jnp.disableDiscovery", "true"); 
            InitialContext ctx = new InitialContext(props);
            return ctx.lookup(jndipath);
        } catch (NamingException e) {
            e.printStackTrace();
        }
        return null;
    }
}


index.jsp调用页面:
Java code
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="com.test.ejb3.HelloWorld,com.web.util.EJBFactory;"%>
<%
        HelloWorld helloWorld = (HelloWorld) EJBFactory.getEJB("HelloWorldBean/remote");
        out.println(helloWorld.SayHello("Good")+"<br/>");
%>




在浏览器中打开index.js
出现错误:
Java code
javax.naming.NameNotFoundException: Name HelloWorldBean is not bound in this Context


我把EJBFactory 的代码改为:
Java code
            props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); 
            props.setProperty("java.naming.provider.url", "jnp://127.0.0.1:1099"); 
            props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); 


在浏览器中打开index.js
出现错误:
Java code
javax.naming.CommunicationException: Could not obtain connection to any of these urls: 127.0.0.1:1099 [Root exception is javax.naming.CommunicationException: Failed to connect to server 127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server 127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]]


HTML code
http://u.115.com/file/f6f9a05f70
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: