File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JNLP and Web Start and the fly likes how to store state? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JNLP and Web Start
Bookmark "how to store state?" Watch "how to store state?" New topic
Author

how to store state?

Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
I have a couple of web start apps that would both benefit from being able to store a string (presumably as a cookie). String is approximately 200 char. I saw some weird code that stored data as a cookie but couldn't make head nor tail of it. Is there a simple way? My apps either get called from the browser or from the desktop.

Many thanks for your time

Mike

PS (one app is an arcade game while the other plays chess)


Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 307
    
    2

Mich Robinson wrote:I have a couple of web start apps that would both benefit from being able to store a string (presumably as a cookie). String is approximately 200 char. I saw some weird code that stored data as a cookie but couldn't make head nor tail of it. Is there a simple way? My apps either get called from the browser or from the desktop.

Hi Mich,

One of us is missing something. If you use a JNLP you are running on the client's machine and you can just ask for permission to write to the disk, create a file and store whatever you need there.

Now if you need to run in a tight security environment you can have the page that launches the app create a cookie and pass it as a parameter in the jnlp which your app can use to communicate with the server. I don't know of a way for a Java app to access the browser's cookie file and it's complicated because the jnlp file can be stored and launched without a browser.

If all you want to do is store a small amount of information, I would mark the jnlp as needing disk access and put a small file in the $HOME directory.

Joe


It's not what your program can do, it's what your users do with the program.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

Another option could be to consider the preference API


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
Joe Areeda wrote:One of us is missing something. If you use a JNLP you are running on the client's machine and you can just ask for permission to write to the disk, create a file and store whatever you need there.
The programs I write are games (arcade games & board games). Users feel fine running a Java app because there is a minimal security risk of viruses etc. If an arcade game pops up a message saying it wants to write to your file system then a fair percentage of potential users will just not want to take the risk. It doesn't really matter that all I wanted to store were high scores and user preferences.

Maneesh Godbole wrote:Another option could be to consider the preference API
I'll look into these. I did try a similar API but I just couldn't get it to work. I'll admit I seem to have a lot more issues trying to run web start applications that applets (I still can't even get the screen icon to show up on the users desktop!). I'll admit I was hoping for a simple pair of methods to call that would write and read a name/value pair (preferably as a cookie or something). Unfortunately nothing is ever as simple as you hope.
Jacob Anawalt
Ranch Hand

Joined: Oct 27, 2010
Posts: 32

To store program state between runs of a Java Web Start deployed app without asking for more permissions you could use the javax.jnlp.PersistenceService, a "cookie-like" mechanism. There is also the FileOpenService and FileSaveService under javax.jnlp if you want users to interact with the save mechanism. These interfaces should be available as long as you are running under web start.

I agree that using these interfaces is not simple when compared to a simple java.util.Properties object or the Preferences API. It often seems easier to sign your code and ask for all-permissions the first time it is run so you can use standard persistence methods.


Jacob
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to store state?
 
Similar Threads
Adding and retieveing values from Cookie
Connect-four
Avoiding dynamic memory allocation in AI board games.
setting cookies on client machine
Fastest chess?