Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/11/2010, 21:38
joise
 
Fecha de Ingreso: octubre-2009
Mensajes: 11
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Applet web POST a PHP

Muchas gracais Nup_ eres el mejor
Me has dejado muy contento, me ha funcionado.
Aca les dejo el codigo para quienes tengan el mismo problema, ya que no lo encontre en ningun

lado, quizas a partir de ahora aprezca este post en google y pueda alegrarle el dia a alguien mas.
Aqui va el htm:
Código HTML:
<HTML>
<HEAD>
<TITLE>
HTML Test Page
</TITLE>
</HEAD>
<BODY>

<applet code="PostXml.class" width=170 height=150>

</applet>
</BODY>
</HTML> 

el class
Código:
import java.net.*;
import java.io.*;
import java.applet.*;
    import java.awt.*;

public class PostXml extends Applet {
String line[]=new String[100];
int i, n;

  public void init() {

try {
// Construct data BR> String data = URLEncoder.encode("key1", "UTF-8") + "=" + 

URLEncoder.encode("value1", "UTF-8");
String data = "&nombre=bruno";

// Send data
URL url = new URL("http://localhost/java/index.php");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();

// Get the response
n=0;
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line[n] = rd.readLine()) != null){
n=n+1;
}

wr.close();
rd.close();
} catch (Exception e) {
}
 }


        public void paint(Graphics g){
      for (int i = 0; i < line.length; i++) {
         g.drawString(line[i],10,10+i*20);
      }
  }

}
el php
Código PHP:
<?php
$nom
=$_POST['nombre'];
$nom.='aaaaa-';



$filename="pep.txt";
    
$archivo=fopen($filename,'a') or die("can't open file");
    
fwrite($archivo$nom);
    
fclose ($archivo);
echo 
$nom;
?>