可以从服务器使用 GWT 属性吗?

发布于 2025-01-04 21:01:17 字数 94 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森末i 2025-01-11 21:01:17

要在客户端中启用 .properties,您可以使用

GWT.create(file_name.properties);

但是这种组合在服务器端不起作用,因为它仅在客户端可用,您会收到此错误:

GWT.create() is only usable in client code!  It cannot be called, for example, from server code.

但是,我想,您可以使用处理 .properties 的标准方法像这样的文件

Properties props = new Properties();
props.load(new FileInputStream("file_name.properties"));

并使用相对路径,而不是绝对路径。应该可以在 GAE 上运行

To enable .properties in client you use

GWT.create(file_name.properties);

But this combination don't work on server-side, cause it's only availible on client-side, you'll get this error:

GWT.create() is only usable in client code!  It cannot be called, for example, from server code.

But, I suppose, you can use standard approach of processing .properties files like

Properties props = new Properties();
props.load(new FileInputStream("file_name.properties"));

And use a relative path, not an absolute path. It should work on GAE

栩栩如生 2025-01-11 21:01:17

使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文