High Score and Applet

Dear All,

I'm trying to put a high scroe system in my applet (game). Therefor I would like to write a file (that is located on my ftp server) were I can save the scores. But how do I acces that File ? With an aplication it's easy, but applet doesn't do it (not even offline) I have thought about the following solutions:

1) Direct acces file and change it (read, change,safe)

2) Download the file to temp directory of user en edit is en then upload it trough FTP

3) Save the high scores in a database ?

I get the following error if I try to use the same code as in a application:

--

java.security.AccessControlException: access denied (java.io.FilePermission highscore.txt write)

at java.security.AccessControlContext.checkPermission(Unknown Source)

at java.security.AccessController.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkWrite(Unknown Source)

at java.io.FileOutputStream.<init>(Unknown Source)

at java.io.FileOutputStream.<init>(Unknown Source)

at java.io.FileWriter.<init>(Unknown Source)

at Bestandentest.init(Bestandentest.java:24)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

-

Please Help me

[1369 byte] By [DukeNukema] at [2007-11-26 17:40:47]
# 1

When you FTP, you're opening a network connection from a user's machine, and that is strictly forbidden in an applet. Writing a file on the user's machine is also strictly forbidden. If you want to save the data in a database, you're going to have to communicate that data back to a server somehow.

Try signing your applet. They click okay, and your applet gets application privileges. One of your other alternatives is Java Web Start.

http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/rsa_signing.html

http://java.sun.com/products/javawebstart/

kevjavaa at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 2
So I don't Use FTP but give my applet a certificate and then I can connect to my webserver ? Because naturly the file with the high scores is on my webspace and not on the visotor's pc.
DukeNukema at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 3

> So I don't Use FTP but give my applet a certificate

> and then I can connect to my webserver ? Because

> naturly the file with the high scores is on my

> webspace and not on the visotor's pc.

If this is the case why don't you host a page of the high scores and use a JEditorPane to display it, in your app.

zadoka at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 4

1. If you just want the user to keep track of their own high score, you could use a signed applet and a local file. What might be more fun in this case is for applet <--> JavaScript communication and storing the score in a cookie.

2. If you want to store global high scores on a server machine, then I would write a servlet to handle revealing the high score info and posting new high scores.

DrLaszloJamfa at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 5

@ zadok : If I use this I can nog save other players there high scores.

@Dr : I want a global high score for the game and keep it on my server. In a file or database. Because I thought I couldn't save it in an applet. A cookies doesn't solve the problem here unfornutly

Whats's a servlet ?

DukeNukema at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 6

> @ zadok : If I use this I can nog save other players

> there high scores.

You would still need to send it back to the server see DrLaszloJamf 's post. The advantage here is that you could make changes to the format of the table and not have to change to program.

> @Dr : I want a global high score for the game and

> keep it on my server. In a file or database. Because

> I thought I couldn't save it in an applet. A cookies

> doesn't solve the problem here unfornutly

I think that is what he is saying.

>

> Whats's a servlet ?

Google.

zadoka at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 7
Thanks i'll google SERVLET and look for a way to make A servlet from my game instead of a Applet, then I can comunicate with a file, writh ?Or do I have to export data from my applet to the servlet ?
DukeNukema at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 8
Servlets are part of J2EE, so if you've never done it before, saying "I think I'll just whip off a servlet" is a bit like saying "I think I'll perform some quick brain surgery on myself, usng a pen knife and a shaving mirror".
DrLaszloJamfa at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 9

> Servlets are part of J2EE, so if you've never done it

> before, saying "I think I'll just whip off a servlet"

> is a bit like saying "I think I'll perform some quick

> brain surgery on myself, usng a pen knife and a

> shaving mirror".

Hey, that's how I ended up being a J2EE coder! ;-P

kevjavaa at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 10
I'll folow the tutorials ant try compiling some simple Servlets before making a bigg one.Hopefully It will work
DukeNukema at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 11

>> Servlets are part of J2EE, so if you've never done it

>> before, saying "I think I'll just whip off a servlet"

>> is a bit like saying "I think I'll perform some quick

>> brain surgery on myself, usng a pen knife and a

>> shaving mirror".

> Hey, that's how I ended up being a J2EE coder! ;-P

Thus far I've resisted the urge to perform brain surgery on myself, but I don't work in J2EE. Should I find myself needing to get a J2EE coding job, what would you recommend? A simple trepanation, a full-scale lobotomy, or something in between?

YAT_Archivista at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 12
A trepanation would temporarily ease those J2EE headaches, but a lobotomy would cure them for good.
DrLaszloJamfa at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...
# 13
> When you FTP, you're opening a network connection> from a user's machine, and that is strictly forbidden> in an applet. Not true. You are allowed to open a connection back to the site from where the applet was served.
bckrispia at 2007-7-9 0:08:58 > top of Java-index,Java Essentials,Java Programming...