如何从远程客户端访问实体bean?(How to access entity beans from a remote client?)

系统教程 行业动态 更新时间:2024-06-14 16:57:40
如何从远程客户端访问实体bean?(How to access entity beans from a remote client?)

我在服务器中有这个:

class Person{...}

@Stateless public class HelloServiceBean implements HelloServiceLocal, HelloServiceRemote { public Person getPerson(String name) { return new Person(name); } }

我在我的客户端(在一些不同的JVM中)有这个:

public static void main(String[] a) throws Exception{ String name = "java2s"; HelloServiceRemote service = null; service = (HelloServiceRemote)new InitialContext().lookup("HelloServiceBean/remote"); Person p = service.getPerson(name)); }

当我需要从我的EJB调用getPerson()方法时,它返回一个Person类型的对象,我的客户端将如何理解Person是一个类?

我是否必须在我的客户端(以及HelloServiceRemote类)中重新编写Person类,因此它可以理解什么是Person? 或者我是否必须将Ejb项目包含到我的客户端项目中?

i have this in the server:

class Person{...}

and

@Stateless public class HelloServiceBean implements HelloServiceLocal, HelloServiceRemote { public Person getPerson(String name) { return new Person(name); } }

And i have this in my client (in some different JVM):

public static void main(String[] a) throws Exception{ String name = "java2s"; HelloServiceRemote service = null; service = (HelloServiceRemote)new InitialContext().lookup("HelloServiceBean/remote"); Person p = service.getPerson(name)); }

When i need to call, for example, getPerson() method from my EJB, which return an object of type of Person, how my client is going to understand that Person is a class ?

Do i have to re-write the Person class another time in my client (and also the HelloServiceRemote class), so it can understand what is a Person ? Or do i have to include the Ejb project into my client project ?

最满意答案

您必须在客户端包含jar项目,包含使用的接口,实体和其他实用程序类。

但是在客户端暴露实体Bean并不可取,您可以在http://www.ibm.com/developerworks/websphere/library/bestpractices/ejbs_access_entity_bean.html获取有关此内容的更多信息。

You have to include jar of EJB project at client side containing Interfaces, Entities & other utility classes used.

But exposing Entity Beans at client side is not preferable, you can get more information regarding this at http://www.ibm.com/developerworks/websphere/library/bestpractices/ejbs_access_entity_bean.html

更多推荐

本文发布于:2023-04-13 12:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/b0d65bea5fa5c5a0bb88f107d4079136.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体   客户端   bean   access   client

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!