java applet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christian Galbavy

    #1

    java applet

    Hy!

    My next problem is to make an applet from my program. I have just add the
    "extend applet" to my class and removed the main-method by the start-method
    of the applet.
    I was thinking that this is enough, but it does not work, the file does not
    appear on the server. I have tried to start the applet local and also from
    the server, but it does not work.
    Here is the code:
    *************** *************** ***********
    import java.awt.*;
    import java.applet.*;
    import java.io.*;
    import java.util.*;
    import java.net.*;
    //import java.exception. *;

    public class transfer extends Applet
    {
    public void start (String args[])
    {
    try
    {
    String hostname = "193.171.244.22 0";
    int port = 80;
    InetAddress addr = InetAddress.get ByName(hostname );
    Socket socket = new Socket(addr, port);

    // Send header
    String path = "/mmi/slate/index.php";

    File theFile = new File("E:/Studium/Multi/Projekt/last_2.jpg");
    System.out.prin tln ("size: " + (int) theFile.length( ));
    DataInputStream fis = new DataInputStream (new BufferedInputSt ream(new
    FileInputStream (theFile)));
    byte[] theData = new byte[(int) theFile.length( )];

    fis.readFully(t heData);
    fis.close();

    DataOutputStrea m raw = new DataOutputStrea m(socket.getOut putStream());
    Writer wr = new OutputStreamWri ter(raw);

    String command = "--mango\r\n"
    + "content-disposition: name=\"MAX_FILE _SIZE\"\r\n"
    + "\r\n"
    + "\r\n--mango\r\n"
    + "content-disposition: attachment; name=\"datafile \";filename= \""
    + theFile.getName () + "\"\r\n"
    + "Content-Type: image/jpeg\r\n"
    + "Content-Transfer-Encoding: binary\r\n"
    + "\r\n";

    String trail = "\r\n--mango--\r\n";

    int string_length = (int) (theFile.length () + command.length( ) +
    trail.length()) ;
    String header = "POST "+path+" HTTP/1.0\r\n"
    + "Content-type: multipart/form-data, boundary=mango\ r\n"
    + "Content-length: " + string_length + "\r\n"
    + "\r\n";

    wr.write(header );
    wr.write(comman d);

    wr.flush();
    raw.write(theDa ta);
    raw.flush( );
    wr.write(trail) ;
    wr.flush( );
    System.out.prin tln("gesendet: "+theData.lengt h);

    BufferedReader rd = new BufferedReader( new
    InputStreamRead er(socket.getIn putStream()));
    String line;
    while ((line = rd.readLine()) != null)
    {
    System.out.prin tln(line);
    }

    wr.close();
    raw.close();

    socket.close();
    }
    catch (Exception e)
    {
    System.out.prin tln(e.toString( ));
    }
    }
    }
    *************** *************** ************

    And the html-file:
    *************** *************** *
    <head>
    <applet code="transfer" archive="transf er.jar" width="640" height="300">
    </applet>
    *************** *************** *

    Again, thanks a lot for any answers.

    Christian



  • Igor Kolomiyets

    #2
    Re: java applet

    Is an attempt to access your php script appears in the log on the web
    server?
    Did you try to run your applet in the debugger?
    Is there anything logged on the console?
    Or it just silently runs but does nothing?

    Please clarify.

    Best regards,
    Igor.

    Christian Galbavy ÐÉÛÅÔ:[color=blue]
    > Hy!
    >
    > My next problem is to make an applet from my program. I have just add the
    > "extend applet" to my class and removed the main-method by the start-method
    > of the applet.
    > I was thinking that this is enough, but it does not work, the file does not
    > appear on the server. I have tried to start the applet local and also from
    > the server, but it does not work.
    > Here is the code:
    > *************** *************** ***********
    > import java.awt.*;
    > import java.applet.*;
    > import java.io.*;
    > import java.util.*;
    > import java.net.*;
    > //import java.exception. *;
    >
    > public class transfer extends Applet
    > {
    > public void start (String args[])
    > {
    > try
    > {
    > String hostname = "193.171.244.22 0";
    > int port = 80;
    > InetAddress addr = InetAddress.get ByName(hostname );
    > Socket socket = new Socket(addr, port);
    >
    > // Send header
    > String path = "/mmi/slate/index.php";
    >
    > File theFile = new File("E:/Studium/Multi/Projekt/last_2.jpg");
    > System.out.prin tln ("size: " + (int) theFile.length( ));
    > DataInputStream fis = new DataInputStream (new BufferedInputSt ream(new
    > FileInputStream (theFile)));
    > byte[] theData = new byte[(int) theFile.length( )];
    >
    > fis.readFully(t heData);
    > fis.close();
    >
    > DataOutputStrea m raw = new DataOutputStrea m(socket.getOut putStream());
    > Writer wr = new OutputStreamWri ter(raw);
    >
    > String command = "--mango\r\n"
    > + "content-disposition: name=\"MAX_FILE _SIZE\"\r\n"
    > + "\r\n"
    > + "\r\n--mango\r\n"
    > + "content-disposition: attachment; name=\"datafile \";filename= \""
    > + theFile.getName () + "\"\r\n"
    > + "Content-Type: image/jpeg\r\n"
    > + "Content-Transfer-Encoding: binary\r\n"
    > + "\r\n";
    >
    > String trail = "\r\n--mango--\r\n";
    >
    > int string_length = (int) (theFile.length () + command.length( ) +
    > trail.length()) ;
    > String header = "POST "+path+" HTTP/1.0\r\n"
    > + "Content-type: multipart/form-data, boundary=mango\ r\n"
    > + "Content-length: " + string_length + "\r\n"
    > + "\r\n";
    >
    > wr.write(header );
    > wr.write(comman d);
    >
    > wr.flush();
    > raw.write(theDa ta);
    > raw.flush( );
    > wr.write(trail) ;
    > wr.flush( );
    > System.out.prin tln("gesendet: "+theData.lengt h);
    >
    > BufferedReader rd = new BufferedReader( new
    > InputStreamRead er(socket.getIn putStream()));
    > String line;
    > while ((line = rd.readLine()) != null)
    > {
    > System.out.prin tln(line);
    > }
    >
    > wr.close();
    > raw.close();
    >
    > socket.close();
    > }
    > catch (Exception e)
    > {
    > System.out.prin tln(e.toString( ));
    > }
    > }
    > }
    > *************** *************** ************
    >
    > And the html-file:
    > *************** *************** *
    > <head>
    > <applet code="transfer" archive="transf er.jar" width="640" height="300">
    > </applet>
    > *************** *************** *
    >
    > Again, thanks a lot for any answers.
    >
    > Christian
    >
    >
    >[/color]

    Comment

    • Mark Murphy

      #3
      Re: java applet

      Christian Galbavy wrote:[color=blue]
      > Hy!
      >
      > My next problem is to make an applet from my program. I have just add the
      > "extend applet" to my class and removed the main-method by the start-method
      > of the applet.
      > I was thinking that this is enough, but it does not work, the file does not
      > appear on the server. I have tried to start the applet local and also from
      > the server, but it does not work.[/color]

      Is the applet on the same server as the what you are trying to post to?
      It wont work locally.

      Mark

      Comment

      Working...