Hi,
I need my
applet to interact with
struts. More precisely i need to
exchange serializable objects between applet and struts. Can some one tell me how to handle this in Action class. I tried two options.
1. first i returned null in execute method of Action class after reading from input stream and after writing to output stream. I am successful in reading object from applet. But inside applet i am unable to read the object.In Applet i m getting EmptyInputStream and there for EOF exception
<b>Action Class Code</b>
response.setContentType("application/x-java-serialized-object");
ObjectInputStream ojbin = new ObjectInputStream(request.getInputStream());
Integer i = (Integer)ojbin.readObject();
_log.info("+++++++++++++++++++++++++++++++++= " + i); ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
out.writeObject(new Date());
return null;
<b>Applet Class code<b>
URL url = new URL("http://localhost:8080/inTest.do");
HttpMessage msg = new HttpMessage(url);
msg.setCookie(SESSION_ID, sessionId);
InputStream in = msg.sendPostMessage(new Integer(1117));
ObjectInputStream result = new ObjectInputStream(in);
Object obj = result.readObject();
Date date = (Date)obj;
message.setText(date.toString());
<b>HttpMesssage Helper Class </b>
public InputStream sendPostMessage(Serializable obj) throws IOException {
URLConnection con = servlet.openConnection();
// Prepare for both input and output
con.setDoInput(true);
con.setDoOutput(true);
// Turn off caching
con.setUseCaches(false);
// Set the content type to be application/x-java-serialized-object
con.setRequestProperty("Content-Type",
"application/x-java-serialized-object");
// Send headers
sendHeaders(con);
// Write the serialized object as post data
ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
out.writeObject(obj);
InputStream in = con.getInputStream();
out.flush();
out.close();
return in;
}
2. Someone told me instead returning null from Action class, forward to some other
servlet. And move all functionality from Action to servlet.
3. But then i tried calling this servlet from applet directly. And as it was simple applet servlet communication it worked without any problem.
CAN SOME ONE TELL ME WHAT I AM MISSING. IN CASE OF EXECUTING SERVLET VIA STRUTS FRAMEWORK, I AM GETTING EMPTY INPUT STREAM BUT IN CASE OF EXECUTING DIRECTLY I DONT HAVE ANY PROBLEM.
Thanx in Advance.
-Rajan