Where to store config parameters in GWT?

前端 未结 5 1080
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 09:30

Where I can store configuration parameters in client side? I haven\'t possibility to store parameters in Servlet init parameters(web.xml) (because I must use PHP). So how I

相关标签:
5条回答
  • 2021-01-12 09:48

    To do this you have a following options:

    1. Store data in client side code. GWT compiles down to the javascript and the simplest way to do this is to create a Configuration class with hardcoded values.
    2. Store data in a browser. You can use cookies or HTML5 local storage
    3. Store data on a server side and retrieve them using remote RPC.

    I would recommend you go with third option.

    0 讨论(0)
  • 2021-01-12 09:49

    You can use MultiValuedConfigProperties (see also this other helpful tutorial) to store configuration values. Using them, you can store your configuration in your module's .gwt.xml configuration file. The configuration values will be compiled into the JavaScript output.

    0 讨论(0)
  • 2021-01-12 09:59

    Standard, simple and easy way to store non-constant parametres(such as passwords, or any user data) on client side is cookies. See Cookies

    Constant parameters you can store in hardcode(static fields in some class) or in resoures .properties files(See GWT i18n constants interface).

    PS: I will not recomment you to store password on client side "as is"(it is not safe), instead you can store password hash(md5, for example). Just calculate password hash on server side and store this hash in cookies.

    0 讨论(0)
  • 2021-01-12 10:00

    You will probably be very happy using the Dictionary and Cookie classes in GWT.

    In your html hosting file, you maintain some javascript objects declared as var.

    At module load, call Dictionary class to grab the javascript objects that you have defined to store your config data.

    In this way, you could have a server side managed user- or context- sensitive configuration, because occasionally I use JSP to generate the hosting file. I could manage user configuration as server side cookies stored in a database.

    So ... today is Thursday ... the user has a history of visiting Manchester Utd FC web site every Thur, etc, let me give the user a different config based on context/user-sensitive algorithm. And on Monday mornings, the user config would include ad data for 10 hour energy beverages.

    In this way, your gwt client would not have to request context-sensitive config data from the server.

    But then of course, this is no way to store authentication/security data like passwords. I don't think you should even consider storing authentication/security data in client-side code. Even after javascript obfuscation, storing such data this way is an open invitation to persistence of malicious intent. Such data, if client-side storage is desired, would be best served by client-side cookies, using the GWT class Cookies.

    0 讨论(0)
  • 2021-01-12 10:06

    Storing passwords on client side? OK, if you want to. Just create a class that will hold them, could be a static field, or a singleton object with all the parameters. Could even be the one with entryPoint().

    0 讨论(0)
提交回复
热议问题