Serialize Applet on Remote Server with HTTP connection on Servlet

Discussion in 'Java' started by pcouas, Dec 16, 2005.

  1. pcouas

    pcouas Guest

    Hi,

    I want Seialize an Applet by Network and a Servlet on Tomcat
    I have following, error message, my Servlet Code seems good, where is
    my mistake

    Thanks
    Philippe


    Message d'erreur
    ’^@^E{sr^@
    java.io.NotSerializableException(Vx^@ç~F^V5^B^@^@xr^@^]java.io_Objec
    tStreamExceptiondÃäk~M9ûß^B^@^@xr^@^Sjava.io.IOExceptionl~@sde%ð«^B^@^@xr^@­^Sjav

    a.lang.ExceptionÐý^_>^Z;^\Ä^B^@^@xr^@^Sjava.lang.ThrowableÕÆ5'9w¸Ë^C^@^CL^@­^Ecau

    set^@^ULjava/lang/Throwable;L^@^MdetailMessaget^@^RLjava/lang/String;[^@



    stackTracet^@^^[Ljava/lang/StackTraceElement;xpq^@~^@^Ht^@^Yjava.io_ObjectI­nputS

    treamur^@^^[Ljava.lang.StackTraceElement;^BF*<<ý"9^B^@^@xp^@^@^@!sr^@^[java­.lang

    ..StackTraceElementa Å~Z&6Ý~E^B^@^DI^@


    lineNumberL^@^NdeclaringClassq^@~^@^FL^@^HfileNameq^@~^@^FL^@


    methodNameq^@~^@^Fxpÿÿÿýt^@^Zjava.io_ObjectOutputStreamt^@^WObjectOutputStr­eam.j

    avat^@^LwriteObject0sq^@~^@^L^@^@^A3t^@^Zjava.io_ObjectOutputStreamt^@^WObj­ectOu

    tputStream.javat^@^KwriteObjectsq^@~^@^L^@^@^A8t^@^Xservletgraph.FileServle­tt^@^

    PFileServlet.javat^@^FdoPostsq^@~^@^L^@^@^Bøt^@^^javax.servlet.http.HttpSer­vlett

    ^@^PHttpServlet.javat^@^Gservicesq^@~^@^L^@^@^CUt^@^^javax.servlet.http.Htt­pServ

    lett^@^PHttpServlet.javat^@^Gservicesq^@~^@^L^@^@^@÷t^@/org.apache.catalina­.core

    ..ApplicationFilterChaint^@^[ApplicationFilterChain.javat^@^PinternalDoFilte­rsq^@

    ~^@^L^@^@^@Át^@/org.apache.catalina.core.ApplicationFilterChaint^@^[Applica­tionF

    ilterChain.javat^@^HdoFiltersq^@~^@^L^@^@^A^@..Standa

    rdWrapperValvet^@^YStandardWrapperValve.javat^@^Finvokesq^@~^@^L^@^@^B~Ct^@­Forg.

    apache.catalina.core.StandardPipeline$StandardPipelineValveContextt^@^UStan­dardP

    ipeline.javat^@


    Cote Applet


    package applet8;
    import java.applet.Applet;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.Button;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.*;
    import java.io.*;
    import java.net.*;


    public class Applet4 extends Applet
    {
    private Button button1 = new Button();


    public Applet4()
    {
    }


    /**
    /**
    * @param args
    */
    public static void main(String[] args)
    {
    Applet4 applet = new Applet4();
    Frame frame = new Frame();
    frame.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });
    frame.add(applet, BorderLayout.CENTER);
    frame.setTitle("Applet Frame");
    applet.init();
    applet.start();
    frame.setSize(300, 300);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    frame.setLocation((d.width - frameSize.width) / 2, (d.height -
    frameSize.height) / 2);
    frame.setVisible(true);
    }


    public void init()
    {
    this.setLayout(null);
    button1.setLabel("button1");
    button1.setBounds(new Rectangle(150, 65, 73, 23));
    button1.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    button1_actionPerformed(e);
    }
    });
    this.add(button1, null);
    }


    private void button1_actionPerformed(ActionEvent e)
    {
    ObjectOutputStream out;
    try
    {
    String m_URL=new
    String("http://172.14.1.141/servlet/servletgraph.FileServlet");
    String string4=m_URL;


    if(string4.indexOf("?")<0)
    string4 += "?";
    else
    string4 += "&";


    string4+="debug=true&";
    string4+="servletname=write&type=object&";
    string4+="cfile=toto.txt";
    URL u=new URL(string4);


    HttpURLConnection urlc = (java.net.HttpURLConnection)
    u.openConnection();
    // Set the Post (true) or Get (false) method.
    urlc.setDoOutput(true);
    urlc.setDoInput(true);
    urlc.setUseCaches(false);
    urlc.setAllowUserInteraction(false);


    urlc.setRequestProperty("Content-type",
    "application/octet-stream");
    // urlc.setRequestProperty("Content-Type", "java-internal/" +
    this.getClass().getName());


    out = new ObjectOutputStream(urlc.getOutputStream());
    out.writeObject(this);


    if (urlc.getResponseCode() != HttpURLConnection.HTTP_OK) {
    System.out.println("Error...");
    // throw new Exception("Access error. ");
    } else {
    System.out.println("I have now access to the stream...");
    // blaha balaaha blaahahaha
    }
    out.flush();
    out.close();


    }
    catch (IOException ioe) {
    System.err.println(ioe);
    ioe.printStackTrace();
    }
    }



    }


    ------------------------------------------------------------
    Coté Servlet

    package servletgraph


    public class FileServlet extends HttpServlet
    {


    public void doPost(HttpServletRequest req, HttpServletResponse
    resp)
    throws ServletException, IOException
    {
    ObjectInputStream in = new ObjectInputStream(req.getInputStream() );
    FileOutputStream file = new
    FileOutputStream(req.getRealPath("/")+czPath);
    ObjectOutputStream out = new ObjectOutputStream(file);
    out.writeObject(in);
    out.flush();
    out.close();
    pcouas, Dec 16, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gordz
    Replies:
    3
    Views:
    3,933
    John Oakes
    Jun 7, 2004
  2. circuit_breaker
    Replies:
    2
    Views:
    1,996
    Jack Jia
    Apr 4, 2004
  3. Tedy
    Replies:
    1
    Views:
    447
    Andrew Thompson
    Aug 4, 2005
  4. pcouas
    Replies:
    14
    Views:
    863
    pcouas
    Dec 28, 2005
  5. lkcl
    Replies:
    6
    Views:
    1,034
Loading...

Share This Page