3

How can I save a configuration locally and permanently in a Java Applet? Ideally this should be work with a not signed Applet.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Horcrux7
  • 23,758
  • 21
  • 98
  • 156

2 Answers2

4

In addition to AlexR's methods..

  1. ..
  2. ..
  3. Run the applet in a new generation Java plug-in (1.6.0_10+) and use the JNLP API's PersistenceService to serialize the data. Here is a demo. of the PersistenceService.
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    +1. IMHO PersistenceService works a little too well and has [privacy issues](http://www.finnw.me.uk/persistencetest.html) similar to Flash's [Local Shared Objects](http://en.wikipedia.org/wiki/Local_Shared_Object), but from a developer point of view it does exactly what you are asking for. – finnw Jan 26 '11 at 13:35
  • Yes, I've heard that comment before. To be honest, I have not even attempted to use the PS in an applet. In fact, at the moment I'm developing a little set of 2D animation applet/applications all deployed using JWS. The application version persists the user preferences, while the applet will not attempt to do so, since everything worth configuring can be done via. an HTML form at start-up. The user can then book-mark the URL. I (vaguely) wonder if Oracle will suddenly decide this is a security problem and shut off applet access to the PersistenceService. – Andrew Thompson Jan 26 '11 at 13:50
2

Applet may receive parameters using <param> tag. This way you can send it parameters you know at design time or at runtime.

If you mean that user that uses the applet can change some parameters and you wish to store them you have 2 possibilities.

  1. Store them in cookies by invoking javascript using JSObject.
  2. Store them on server side. Applet may send the parameters to server using any kind of network connection for example using web service (e.g. RestFull web service). Server stores the configuration and sends it to applet as parameters (using <param> tags) that are generated by JSP. Alternatively applet may retrieve parameters using same web service it used to store them on startup.
AlexR
  • 114,158
  • 16
  • 130
  • 208