为什么在客户端创建的对象在GWT开发模式下无法从服务器端访问? [英] Why an object, created in client side, is not accessible from server side in GWT development mode?

查看:107
本文介绍了为什么在客户端创建的对象在GWT开发模式下无法从服务器端访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发模式下运行我的GWT应用程序。在我的客户端代码(实现入口点的类)中,我创建了一个对象并将其分配给另一个类的静态变量(假设为A类)。

现在,我可以通过从客户端的任何地方引用类A的静态变量来访问该对象,但无法从服务器端代码访问它。任何人都可以解释为什么我无法像访问客户端代码那样访问对象,就像开发模式中在同一个JVM上的同一会话范围内运行的客户端和服务器一样。 / p>

解决方案

即使在开发模式下,您的客户端代码和服务器也不在一个JVM中运行。如你所知,GWT客户端代码被编译成Javascript代码。因此更新一些静态字段最终被编译成更新JavaScript对象的某些属性。



GWT中的开发模式足够智能,并且不允许混合服务器和客户端静态变量,以避免在部署后出现混淆。编译版本到你的服务器。


I am running my GWT application in development mode. In my client side code (Classes that implements Entrypoint), I have created one object and assigned it to a static variable of another class (Suppose Class A).

Now, expectedly I can access the object by he reference of the static variable of class A from anywhere from the client side but can't access it from the server side code. Can anybody explain me why I can't access the object the same way I accessed it from client side code as both the client and server running within the same session scope on the same JVM in development mode.

解决方案

Your client side code and server are not running inside one JVM, even in a dev mode. As you know, GWT client code is compiled into Javascript code. So updating some static field is eventually compiled into updating some property of Javascript object. In can not be accessed by Server side code for obvious reasons.

Dev mode in GWT is smart enough and not allows to mix Server and Client static variables to avoid confusion after deploying compiled version to your server.

这篇关于为什么在客户端创建的对象在GWT开发模式下无法从服务器端访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆