Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

HTTP POST to a php script

807597Aug 21 2005 — edited Feb 8 2006
I have a java applet and I need to write to a file, since I can't do that directly, I am calling a php script to write to the file. Here is the relevant code in the .java file
URL myURL=null;
URLConnection urlConn=null;
DataOutputStream printout=null;
DataInputStream input=null;
try{
	myURL=new URL(getCodeBase(),"writeFromFile.php");
	}catch(Exception easidghih){JOptionPane.showMessageDialog(null,"WRITETOFILE");}	
try{
	urlConn=myURL.openConnection();
	}catch(Exception w){JOptionPane.showMessageDialog(null,"openConnection()");w.printStackTrace();}
try{urlConn.setDoInput(true);
	urlConn.setUseCaches(false);
	}
catch(Exception a){JOptionPane.showMessageDialog(null,"Exception here");}
try{
	urlConn.setDoOutput(true);
	PrintWriter out=new PrintWriter(urlConn.getOutputStream());
	out.println("File="+username+"P.txt"+"&text="+(Long.toString(number)));
	out.close();
the text of the php file, "writeFromFile.php" is below.
<HTML>
<BODY>
<?php
print "BOB";
$File=$_POST["File"];
$text=$_POST["text"];

$filename=$File;
$fp=fopen($filename,"w");
$string=$text;
$write=fputs($fp,$string);
fclose($fp);
?>
</BODY>
</HTML>
The file writing works fine when I have a separate file with a form to fill out in HTML. But when I run the java applet it gives no errors, but the file writing doesn't work.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 8 2006
Added on Aug 21 2005
16 comments
236 views