BlazeDS、Flex 和 Java - 我可以将 RemoteObject 视为 Java 类的实例吗?
如果这个问题有点明显,我很抱歉,但我是 BlazeDS 的新手,似乎找不到答案。我在带有 Flex 前端的 BlazeDS 服务器上运行 Java。我希望能够仅实例化我的 Java 类一次,然后让 Flex 使用 setter 和 getter 来处理 Java 类中的数据(在某种意义上,将 RemoteObject 视为该类的实例) )。据我所知,这似乎是 BlazeDS 的工作方式,但每次我从 Flex 调用任何 Java 方法时,它都会再次调用 Java 构造函数,重置 setter 方法输入的任何内容。有没有办法让服务器在方法调用之间保存 Java 类的实例?谢谢!
I'm sorry if this question is a bit obvious, but I'm new to BlazeDS and can't seem to find an answer. I'm running Java on a BlazeDS server with a Flex front-end. I'd like to be able to instantiate my Java class only once, then have the Flex use the setters and getters to play with the data in the Java class (in a sense, treating the RemoteObject as if it were an instance of the class). As far as I've read this seems to be the way BlazeDS works, but every time I call any Java method from Flex, it calls Java constructors again, resetting anything input by the setter methods. Is there a way to have the server hold the instance of the Java class between method calls? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎误解了这是如何运作的。
Flex 客户端中的对象和服务器上的对象是完全独立的。在正常情况下,Flash Player/Flex 应用程序仅使用 WebSerice、HTTPService 或 RemoteObject 与远程服务通信。 RemoteObject 通过 BlazeDS、LiveCycle Data Services、ColdFusion 和大量其他服务器端软件支持 AMF 和 Flash Remoting。
当您对服务器进行远程调用时,该请求与标准网页调用没有什么不同。它以“孤立”的方式存在,对任何其他调用一无所知。在传统的 HTML 开发中,我们使用会话 cookie 来跟踪“无状态”客户端中的服务器会话。 Flex 调用也是如此。如果您的服务器在客户端设置了cookie;然后 Flash Player 将在每个请求中包含这些 cookie;将服务调用与服务器端会话相匹配。
每次调用是否创建对象取决于远程调用的作用。
AMF / RemoteObject 提供的好处是它可以轻松地将服务器端对象(Java 类)转换为客户端对象(ActionSCript 类)。这主要用于在两个不同实体之间传递数据。通常人们为此创建值对象/数据传输对象;但这些类可以具有完全相同的功能。 Flex 和 Java 中并不存在同一个对象。
这有帮助吗?
You seem to have a misunderstanding of how this is works.
Objects in the Flex client and Objects on your server are completely independent. In normal circumstances, The Flash Player/A Flex App only talks to the remote service using either a WebSerice, HTTPService, or RemoteObject. RemoteObject supports AMF and Flash Remoting with BlazeDS, LiveCycle Data Services, ColdFusion, and a ton of other server side software.
When you make remote calls to the server, that request is no different than a standard web page call. It exists in "isolation" and knows nothing about any other call. In traditional HTML development we use session cookies to keep track of server sessions in a 'stateless' client. The same can be true for Flex calls. If your server sets cookies on the client; then the Flash Player will include those cookies in each request; matching up the service call to a server side session.
Whether an object is created with each call depends on what your remote call does.
The benefit that AMF / RemoteObject offers is that it can easily translate server side objects (Java Classes) to client side objects (ActionSCript classes). This is primarily used for passing of data between the two different entities. Usually people make Value Objects/Data Transfer Objects for this; but the classes can have the same exact functionality. It is not like the same object exists in both Flex and Java.
Does that help?