Solved

Writing files inside an applet

Posted on 1998-05-08
8
182 Views
Last Modified: 2013-11-24
Okay, I'm wanting to create an applet that saves the information from the applee on to the host computer, or the web server that the applet is being posted on.  I know I can't write files or read files to the client but I should be able to read and write to the host computer.  I'm trying to implement something similar to a highscores table that saves information from an applet that lots of people will use, like a voting thing......
0
Comment
Question by:GreenK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 3

Expert Comment

by:hkp
ID: 1220842
I can imagine two ways to write files. One is to use the FTP protocol (this is long hair), and the other is to use the File() class. Here's a sample of the later, although I see trouble ahead from an applet (I assume, the c: drive is the webserver's):

// Create a file, if non-existent.
File f = new File("c:/","test.txt");
if ( f.exists() == false) {
try {
FileWriter fw = new FileWriter(f);
fw.write("123",0,3);
fw.flush();
fw.close();


}
catch (IOException e) {
e.printStackTrace();
};
}
f=null;


I hope this can get you on better ground.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1220843
GreenK, as far as I understand you want to do it from the client to the server, in java. What you should do is open a URL to the server to a location that you can write in, get the URLConnection, get an outputStream and write. The http server must enable the writing operation though.
0
 

Expert Comment

by:DonReese
ID: 1220844
GreenK, consider opening a connection back to your webserver and post the information to a CGI-BIN that handles all the file work.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 3

Expert Comment

by:hkp
ID: 1220845
I think a good solution would require the use of CGI by means of a Java servlet, which handles the highscore table file updates and representations.

By using a URLConnection, you should be able to send parameters from your applet to the servlet via the URL.

If you don't have experience with Java servlets, this is a longer story. Look at http://java.sun.com/products/index.html and lookup the Servlet Development Kit, install it on the web server machine. Make your first servlet, and use the above code principles for writing to a file on the server.

:-)

0
 

Author Comment

by:GreenK
ID: 1220846
Can't use new File because that accesses files on the client machine..and we can't write to that because it's an applet....

So I've created the perl cgi files to do all the file handling...

Now i'm trying to figure out how to pass the information to the perl file..
I've got it setup where a form can alter the data using the get method..

script.cgi?data1+data2+data3

So how do I pass that to perl using java stuff....


0
 
LVL 4

Expert Comment

by:evijay
ID: 1220847
write a proxy server on the host from which the applet is originated.

A proxy server is another java program that listens at a known serversocket. Your applet can connect to the proxy server, send the data to it, and the proxy server inturn writes / reads the files onto the host harddisk.

check for a java telnet applet from site
http://www.first.gmd.de/persons/leo/java/Telnet/ 

This is a very good example of writing a proxy server to overcome the security restrictions of applets.



Vijay
0
 

Author Comment

by:GreenK
ID: 1220848
The answer was rejected because your idea would only work if I was trying to write to the host computer and not the webserver computer that is hosting the applet.

This is going to be a game that keeps track of the highscores of everyone that plays....this file that they write to needs to be centrally located on the server.


0
 
LVL 4

Accepted Solution

by:
evijay earned 50 total points
ID: 1220849
write a proxy server on the host from which the applet is originated.
A proxy server is another java program that listens at a known
serversocket. Your applet can connect to the proxy server, send the data
to it, and the proxy server inturn writes / reads the files onto the
host harddisk.
check for a java telnet applet from site
http://www.first.gmd.de/persons/leo/java/Telnet/ 
This is a very good example of writing a proxy server to overcome the
security restrictions of applets.
Vijay
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 161
jsp login check 12 67
Netbeans and org.apache.commons.lang3 issue 3 55
Session in java desktop 5 39
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question