Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing text files on a webserver

 
Andreas Beck
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys!
I'm currently working on an JApplet that has to read and write .txt files on the webserver it is running on.
Reading is no problem, but writing is difficult. My temporary solution is:

The parameters name and score are then saved in a .txt file with php (GET).
The problem here is that I can cheat by e.g. entering www.website.com/game.php?name=Andy&score=9999999999
In my applet I have more than the two variables in the example above, which makes the url long and ugly. Also, the website always has to reload the applet when it is writing files.

My Question now is:
How can I write files to the webserver without displaying the data to the user (and, if possible, without reloading the page)? I have searched the internet for over 1 week now and I haven't found a solution. Some people suggest using Servlets and I have already seen some tutorials and example servlets, none of which has written data to the webserver's file system . Others talk about policy files or signed applets, but I don't know how this works.

If someone knows a solution for my problem, could you please provide a small code example, like how to write "Hello World" in a file "www.website.com/data/hello.txt"? That would be awesome! All other help is highly appreciated, too. ;)
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andreas Beck wrote:
How can I write files to the webserver without displaying the data to the user (and, if possible, without reloading the page)? I have searched the internet for over 1 week now and I haven't found a solution.


You can use Java code to write data to a URL. see this example. If someone is suggesting servlets, they are talking about the server-side part of the equation, which you apparently are using PHP to do.
 
Andreas Beck
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick answer! You're my hero if I can get this to work!

So you're suggesting I should write a method in my applet code like:


Correct? And how can my php script access the variables? Via POST? Or GET? And do I have to reload the webpage that contains the applet or can I create and edit .txt files while running?
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code tags to your post. Please use them as it makes the code easier to read.
This line:


sets the request to be POST. I don't do PHP, so you'll have to figure that side out.
You don't need to reload the page unless you are displaying values that have been uploaded on that page (and even then, you could use AJAX to load content without reloading the page).
 
Andreas Beck
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I will try this.
 
Andreas Beck
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for your help, I have the solution now. I used URLConnection to write data to

In writeData.php I simply got the values via $_POST["var0"] and $_POST["var1"].
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!