This week's giveaway is in the Java/Jakarta EE forum. We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line! See AppletServlet communication using the struts framework. Can you give me some links?
thanks for the fast answer. I already know both articles and have done some Applet-Servlet programming for a project myself. Maybe I formulated my question wrong. Sorry for this!!!
I'm especially interested in Applets which interact with Servlets which use the Struts framework. How to do ActionForwarding to an applet, how to write the struts-config.xml file for such a case and so on...
We use the same framework. We create an object or collection to be returned to the Applet in the action, and then forward the object to the applet. To achieve this - we do the following:
1. From applet, we open the URLConnection with the URL for an Action.
2. At the end of Action class, we retrieve the object from middle tier (business logic tier)to be returned to the applet.
3. We use Castor to marshal the object to XML String and put the XML String in request attribute
4. We forward to "success" which is mapped to a jsp. The content of the jsp file is
5. The XML String now arrives to applet as input stream. Read the input stream from the URLConnection and form the XML String.
6. Use Castor unmarshal to get back the object in the Applet.
posted 13 years ago
Can you explain me step 3.-5. a little bit more in detail? So, why do you use Castor and not normal object serialization? Do you have a link or example source code?
posted 13 years ago
Step 3 is required to convert the object to XML String. We tried with Java Object Serialization before, but at that time our development environment was VAJ 3.5.3 and the serialized object in VAJ Test Environment had problem while being unmarshalled in Sun 1.4.1 JDK - I do not remember the exact exception message, but as far as I can recall, we used to get Corrupted Stream exception. But, if effect, that would throw us out of VAJ IDE. We also tried JSX, instead of Castor, and JSX works too. You could use JSX or any other kind of XML Serialization.
Regarding, Step 4 and 5 - as the HTTP Connection originated from Applet, hence, all the response will end up going to the URLConnection input stream of the Applet, which initiated the connection. No matter, where you forward your response to, the response stream could be read by reading on input stream of the URLConnection.
Here is example code from applet,
Now, we have byte array from the response, convert the array to String, which is really the object marshalled to XML.