您的位置:程序门 -> java -> j2ee / ejb / jms



servlet 怎样调用 部署在jfox中的 ejb3.0


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


servlet 怎样调用 部署在jfox中的 ejb3.0[已结贴,结贴人:beibeig]
发表于:2007-06-08 12:45:37 楼主
写了一个简单的ejb3.0的程序,并且部署到了jfox中,想在tomcat中通过servlet调用,请问怎么调用?最好给个简单servlet的例子.
以下是我写的ejb3.0的小例子

------------------------------------------------
package   com.test;

public   interface   hello  
{
        public   string   hello();
}

------------------------------------------------
import   javax.ejb.remote;
import   javax.ejb.stateless;

@stateless
@remote(hello.class)
public   class   hellomyconfig   implements   hello
{
        public   string   hello()
        {
                string   strresult   =   " ";
                try
                {
                        strresult   =   "hello   world. ";
                        system.out.println(strresult);
                }
                catch   (exception   ex)
                {
                        ex.printstacktrace();
                        strresult   =   "error ";
                }
                return   strresult;
        }
}
----------------------------------------

我的客户端掉用(在jboss中跑过)
---------------------------------------
import   javax.naming.context;
import   javax.naming.initialcontext;

public   class   helloclient
{
        public   static   void   main(string[]   args)   throws   exception
        {
                context   ctx   =   new   initialcontext();
                hello   hello   =   (hello)   ctx.lookup( "hellomyconfig/remote ");

                system.out.println(hello.hello());
        }
}
发表于:2007-06-08 13:19:361楼 得分:100
context   ctx   =   new   initialcontext();
hello   hello   =   (hello)   ctx.lookup( "hellomyconfig/remote ");
一样的,这段放在servlet的doget或者dopost中
不过ejb3的bean可以通过annotation注入的
发表于:2007-06-08 13:54:242楼 得分:0
楼上的可不可以贴个完整的代码看一下呀
谢谢先
发表于:2007-06-08 14:10:563楼 得分:0
context   ctx   =   new   initialcontext();
                hello   hello   =   (hello)   ctx.lookup( "hellomyconfig/remote ");

---------------------------------------------------------------------------
这种形式是在jboss中用的
我想知道   在jfox中是不是也这样调用?

我写了个jsp调用     报错了

------------------------------jsp代码---------------------------------------
<%@   page   contenttype= "text/html;charset=utf-8 "   language= "java "   %>
<html>
<head>
        <title> jsp   invoke   ejb </title>
        <%@page   import= "javax.naming.context "   %>
        <%@page   import= "javax.naming.initialcontext "   %>
        <%@page   import= "com.test.hello "   %>
        <%@page   import= "com.test.hellomyconfig "   %>
       
</head>
<body>

<h1> jsp   invoke   jfox   ejb   test </h1>
<p>

<%
                context   ctx   =   new   initialcontext();
                hello   hello   =   (hello)   ctx.lookup( "hellomyconfig/local ");
                //   system.out.println(hello.hello());
                //   out.print(hello.hello());
%>

</body>
--------------------------end-----------------------------------------------

错误信息:
exception  

org.apache.jasper.jasperexception:   javax.servlet.servletexception:   javax.naming.namenotfoundexception:   name   hellomyconfig   is   not   bound   in   this   context
。。。。。。

发表于:2007-06-08 16:51:084楼 得分:0
郁闷     这么快就要沉底了


快速检索

最新资讯
热门点击