Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Applet to Servlet Communication  RSS feed

 
Jan Wayne
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
I`ve an Applet and an Servlet which should exchange a Object, here
I took a Hashtable. First, the Servlet opens a ObjectOutputStream to the
Applet to send a Hashtable object. This works fine, and after that the
Applet opens another ObjectOutputStream to the Servlet. But I cannot compile the Servlet, it can`t read s.th. and throws a EOFException.
Here`s the Applet-Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class a extends Applet implements ActionListener
{

public void init()
{
try{

URL url = new URL(getCodeBase(), "/servlets-examples/servlet/s");
URLConnection con = url.openConnection();

InputStream in = con.getInputStream();

ObjectInputStream result = new ObjectInputStream(in);

Hashtable htResult = (Hashtable) result.readObject();
loop = ((Integer) htResult.get("anzahl")).intValue();
in.close();
catch (Exception eEx)
{
System.out.println("problem: "+eEx);
}



}
public void actionPerformed(ActionEvent e)
{


try
{
senden();//Aufruf
}
catch(Exception k)
{
System.out.println("Fehler beim Start der Methode senden()");
}

}
public void senden()
{
try
{

URL url = new URL(getCodeBase(), "/servlets-examples/servlet/s?request=out");
URLConnection connect = url.openConnection();
connect.setDoOutput(true);

OutputStream out = connect.getOutputStream();

ObjectOutputStream result = new ObjectOutputStream(out);

Hashtable stuff = new Hashtable();
stuff.put("wert", "just a notice");
result.writeObject(stuff);

result.flush();
System.out.println("-flush-");
result.close();
}
catch(Exception f)
{
System.out.println(f);
}
}
}

And here`s the Servlet- Code:

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class s extends HttpServlet {
public void init()
{
}

public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
System.out.println("---------------Servlet-Start---------------------");
System.out.println("servlettest: Method service: " + req.getParameter("request"));
Hashtable htData = new Hashtable();

System.out.println("servlettest: Verbindung zum Applet aufgebaut");
ObjectOutputStream out = new ObjectOutputStream(res.getOutputStream());


htData.put("key", "value" );


out.writeObject(htData);
out.flush();
out.close();

try
{

ObjectInputStream flow = new ObjectInputStream(req.getInputStream());

//System.out.println("result: "+flow.readObject());
//flow.close();
}
catch(Exception h)
{
System.out.println("problem-->: "+h);
}
}//end of service
}
I hope you can help me with this problem, thank you!!
Jan
 
Jan Wayne
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for this long code,
I forgot I�m using Tomcat 5.0.1.2 and Java- Version 1.3.1.
Could it make sense, that this Tomcat-Version is the cause for
EOFException?
Here`s s.th. I found
web page
Thanks again for your help!
Jan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!