Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

Bo Koralage

Greenhorn
+ Follow
since Mar 16, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bo Koralage

Thanks for your response. I will give that a try.
Bo
19 years ago
To the remote host where the applet came from. I already wrote a security policy on the local host to give that permission. I am using the Java plugin so all users will use the JRE which was the best way I saw to keep all users consitant. Thanks for taking the time to help
Bo
19 years ago
All of these suggestions sound good, but they all require other java apps or servers to be wrtten. I would think that applets should be able to write a basic text files. Is this a limitation of Applets?
Basically I don't know why I have to implement a whole other server app to just write a basic text file. Seems like Sun shoud provide some functionality for this. Please tell me your thoughts
Thanks
Bo
19 years ago
Yes that works for reading a file. But I am still not able to write to a file. Here is my last try.
String fileName = "data/temp.dat";
URL url = new URL(calApplet.getDocumentBase(), fileName);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
out = new PrintWriter(connection.getOutputStream());
out.write("This is a test",0, outString.length());
out.write('\n');
Before this when I had the Applet as a file in the dirctory I was using FileWriter and I didn't have any problems. The FileWriter doesn't seem to work when going from a webserver. I would appreciate any help.
Thanks
Bo
19 years ago
Well I finally I got the Applet to read and write a file. What I had to do was to write a new security policy and add that new policy to my java.security file in the JRE folder. I also required users to use the java plugin. Now I am in the process of moving my files to a web server. The problem I am running into is reading the file from withing the server. I am still using the original code I was used to read the file.
String fileName = "data/test1.dat";
URL url = new URL(myApplet.getDocumentBase(), fileName);
File datFile = new File(url.getFile());
System.out.println(datFile);
if (datFile.exists()){
BufferedReader in = new BufferedReader(new FileReader(datFile));
String line = in.readLine();
....
}

I put in the println for debugging. On the java console it does show me a valid directory file path. However, I am not getting any data for my app and I don't get any security violations.
I guess the bottom line is can an applet open a file from a root webserver directory just as opening one on the file system. Any help you can give is greatly appreciated.
Thanks
Bo
19 years ago
Cool, This will work. Thanks for your help. I really wish that the Appletviewer and java plugin would behave in a consistant fasion. It would really help us developers
19 years ago
Well about signing or giving permission to applets I have had no luck so far. I went through resources you gave and tried to follow few of the examples from sun. I am not clear about setting properties and signatures. Is there any simple example I can look at. All I need to do is to read and write to the server where the applet came from. Thanks for your help
Bo
19 years ago