可以从服务器使用 GWT 属性吗?
我有一个 GWT 应用程序,它使用 GWT RPC 与 App Engine servlet 进行通信。我想使用服务器上 .properties 文件中定义的常量。这可能吗?
I have a GWT app that uses GWT RPC to talk to App Engine servlets. I would like to use constants defined in a .properties file on the server. Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要在客户端中启用 .properties,您可以使用
但是这种组合在服务器端不起作用,因为它仅在客户端可用,您会收到此错误:
但是,我想,您可以使用处理 .properties 的标准方法像这样的文件
并使用相对路径,而不是绝对路径。应该可以在 GAE 上运行
To enable .properties in client you use
But this combination don't work on server-side, cause it's only availible on client-side, you'll get this error:
But, I suppose, you can use standard approach of processing .properties files like
And use a relative path, not an absolute path. It should work on GAE
使用 GWT 字典类。
在 html 托管文件中声明 javascript 对象,然后在 onModuleLoad 之后随时使用 Dictionary 检索它们。
使用 JSP 构建您的 html 托管文件 - 这样您就可以拥有一组动态服务器生成的常量。您可以拥有一组用户敏感的常量。您的 servlet/jsp(JSP 本质上是 servlet)将能够读取服务器上其范围内的任何属性文件或任何数据库记录,以创建这些常量。
阅读此答案:GWT 平台登录 + 会话管理。
Use the GWT Dictionary class.
Declare you javascript objects in your html hosting file, then use Dictionary to retrieve them anytime after onModuleLoad.
Use JSP to construct your html hosting file - so that you could have a dynamically server generated set of constants. You can have a user-sensitive set of constants. Your servlet/jsp (JSPs are essentially servlets) would be able to read any property file or any database record within its reach on the server to create those constants.
Read this answer: GWT-Platform login + session management.