The Artima Developer Community
Sponsored Link

Java Answers Forum
passing serialized object from servlet to applet

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jose Pereira

Posts: 1
Nickname: pereira
Registered: Aug, 2002

passing serialized object from servlet to applet Posted: Aug 16, 2002 1:56 PM
Reply to this message Reply
Advertisement
hi,

I have a problem with servlet-applet communication and I wonder if anyone could help me.
I want to pass a serialized object 'myObj' from the servlet to the applet. The applet calls the servlet.
I'm using the following code:

----------SERVLET
public void doGet(...) {
 
	String action = (String)req.getParameter("action");	
 
	if (action.equals("GetMyObject")){
	    try {
		res.setContentType("application/x-java-serialized-object");
		ObjectOutputStream out = new ObjectOutputStream(res.getOutputStream());
		MyClass myObj = new MyClass();
		out.writeObject(myObj); 
		out.flush();
	    }
	} else { doSomethingElse(); }
}

----------APPLET
...
URL    currentPage  = getCodeBase();
	String protocol     = currentPage.getProtocol();
	String host         = currentPage.getHost();
	int    port         = currentPage.getPort();
	String urlSuffix    = "/servlet/myServlet?action=GetMyObject";
	URL    dataURL      = new URL(protocol, host, port, urlSuffix);
 
	URLConnection connection = dataURL.openConnection();
	connection.setUseCaches(false);
	connection.setDoInput(true);
	connection.setDoOutput(true);
	ObjectInputStream in = new ObjectInputStream(connection.getInputStream());
	MyClass myObj = (MyClass)(in.readObject());
	in.close();

---------------------------------------------------------------
Any ideas please..

many thanks

Jose Pereira

Topic: JFrame help Previous Topic   Next Topic Topic: HELP NEEDED! easy job!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use