File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes How applet talk to another applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "How applet talk to another applet " Watch "How applet talk to another applet " New topic

How applet talk to another applet

Pira Tomatsu

Joined: Sep 01, 2009
Posts: 14
I got a requirement to build a web application to upload pictures.

A signed JFileChooser to used to select pictures at Client-Side.
After pictures are selected, paths of all pictures have to send to another viewer applet to display(each picture for each applet).
This viewer applet is written by others and it only receives a path of a picture to display through <param> tag.

The question is how JFileChooser applet can send paths of all pictures to the viewer applet.

Sorry for my bad english, hope you can understand. Thank you for your answer.
Pira Tomatsu

Joined: Sep 01, 2009
Posts: 14
I have more questions. How I can upload multiple files (selected pictures) to a server.

Right now I have no ideas about uploading multiple files. I only know how to write a file at a time.
I use FileIn/OutStream to write to a shared folder which share data with a server instead.
Is it ok to do this?

Thank you again
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Welcome to JavaRanch.

First off, be aware that using a shared folder limits the use of the applet to everybody who can access that folder - say, everybody on the same company network. Nobody outside the firewall will be able to use it. Just something to keep in mind.

Something else to keep in mind is how to organize the files in the shared directory: How do they get unique names? How do you make sure that files uploaded by different users don't have the same names and so overwrite each other? How can a user go back to view all the files she has uploaded? How does the code know which user has uploaded which file?

JFileChooser can only select a single file. If you want to upload multiple files you'll have to invoke it multiple times and upload each selected file individually.

As to transferring control to a different applet, the upload applet needs to remember all names/paths of the files. Then it can either use the AppletContext's showDocument method to switch control to a different page that contains the viewer applet (and pass all file names in the URL), or it can first save the file names to the server (by doing an HTTP POST to a servlet or similar), and then call showDocument to a server URL that knows about the previously POSTed file names, and which can then create the page with the viewer applet and add all the filenames as <param> tags to the <applet> tag.

The former approach (passing filenames in the URL) limits you to just a few files, since URL are generally restricted to 2000 characters or so.
I agree. Here's the link:
subject: How applet talk to another applet
It's not a secret anymore!