Serialize Applet on Remote Server with HTTP connection on Servlet

P

pcouas

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^@[email protected]

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();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top