File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Applet Servlet communication with struts? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Applet Servlet communication with struts?" Watch "Applet Servlet communication with struts?" New topic

Applet Servlet communication with struts?

Torsten Schindler

Joined: Aug 18, 2004
Posts: 13
Hi *,

I'm looking for some information/web sites, how to program a
Applet Servlet communication using the struts framework.
Can you give me some links?


Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

I dont know if struts has any special facilities for this, but here is a pretty good article that discusses applet-servlet communication in general.

Applet-to-Servlet Communication for Enterprise Applications

Apparantly someone else found it very useful too

The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
Torsten Schindler

Joined: Aug 18, 2004
Posts: 13

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...


Susanta Chatterjee
Ranch Hand

Joined: Aug 12, 2002
Posts: 102
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.

Torsten Schindler

Joined: Aug 18, 2004
Posts: 13
Hi Susanta.

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?


Susanta Chatterjee
Ranch Hand

Joined: Aug 12, 2002
Posts: 102
Hi Torsten,

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.

Hope this helps.
I agree. Here's the link:
subject: Applet Servlet communication with struts?
It's not a secret anymore!