Results 1 to 1 of 1
- 01-07-2011, 12:17 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 1
- Rep Power
- 0
Java applet post get method to php
Hi,
I'm trying to use a php script to save a file but the's no way to see it work invoked by an applet
The php script works correctly if invoked via html
Here follows the java and php code.
---java---------
import java.applet.Applet;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.io.Writer;
public class wFile1 extends Applet{
public String str;
public void init(){
}//init
public void paint(Graphics g){
boolean b = true;
g.drawString("Start paint",1,10);
b=Writ_e("What_File_Contains");
g.drawString(str,1,20);
if (b == true)
g.drawString("Ok",1,30);
else
g.drawString("Fail",1,30);
}//paint
public boolean Writ_e(String varFileContent)
{
boolean log = false;
try
{
String params = URLEncoder.encode ("FileContent", "UTF-8") + "=" +
URLEncoder.encode (varFileContent, "UTF-8");
URL url = new URL ("http://127.0.0.1/wFile1.php");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
out.write(params);
str = params;
log = true;
}//try
catch (IOException a)
{
System.out.println("Error URL 2");
}//catch
return log;
}//Writ_e
}//wFile1
---php----------
<html>
<body>
<?php
$FileContent = $_POST['FileContent'];
$fn = "wFile1.txt";
$fp = fopen($fn,"w");
flock($fp,2);
fputs($fp,$FileContent);
flock($fp,3);
fclose($fp);
/*verify*/
$fn = "wFile2.txt";
/* writes a verify file */
$fp = fopen($fn,"w");
flock($fp,2);
fputs($fp,"verify");
flock($fp,3);
fclose($fp);
?>
</body>
</html>
someone can help me please?
Thank you very much
Similar Threads
-
Passing parameter from JApplet to php file using POST method
By mneskovic in forum New To JavaReplies: 10Last Post: 08-05-2010, 05:27 PM -
HTTPS POST Using Java
By drcman in forum Advanced JavaReplies: 7Last Post: 02-13-2010, 02:19 PM -
DOnt know if 1st post if did, I am VERY sorry for duplicate post. I have error messg
By afisher300 in forum New To JavaReplies: 3Last Post: 05-04-2009, 03:15 AM -
Post Method in java.net
By freddieMaize in forum Advanced JavaReplies: 2Last Post: 02-23-2009, 02:59 AM -
post and redirect from within an applet
By gtriant in forum Java AppletsReplies: 0Last Post: 03-18-2008, 05:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks