Can GWT Properties be used from the server?

女生的网名这么多〃 提交于 2019-12-22 12:38:54

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/9270664/can-gwt-properties-be-used-from-the-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!