aspose file tools*
The moose likes Applets and the fly likes Applet accessing client's file system Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet accessing client Watch "Applet accessing client New topic
Author

Applet accessing client's file system

Martin Asenov
Ranch Hand

Joined: Aug 05, 2009
Posts: 34
Hi, friends!

I wrote an applet that browses local file system and displays it as a JTree. However, that applet will be placed in a jsp page and hosted on some server. So in order to access client's local file system what kind of connection should I make? And after I make it, how am I supposed to get a certain file, for instance "Drive:\file.extension". Is it through "IP Address\Drive:\file.extension" ? I suppose not.

However, I know that the applet should be signed, and it will be. But before that I have to write the connectivity part. I'll have a controller that will have to build the whole thing.

Please, give me some assistance with that... Thanks in advance!

Best Regards,
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42644
    
  65
Would the applet know the precise location and name of the file to be used? I'm guessing that in most cases it wouldn't. In that case the applet would be better off using a FileDialog or JFileChooser to let the user select the image to be used. The correct path could then be gotten from the FD/JFC instance.


Ping & DNS - my free Android networking tools app
Martin Asenov
Ranch Hand

Joined: Aug 05, 2009
Posts: 34
Well, I use mostly File(someDir).listFiles() in order to get the contents. That's how my Jtree displays the contents. I guess that using the same methods will be able if I first establish connection to the remote (client) PC.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42644
    
  65
What do you mean by "remote"? The files to be shown in the applet reside on the client machine, don't they? So it's all local, no?
Martin Asenov
Ranch Hand

Joined: Aug 05, 2009
Posts: 34
The applet shows the contents on my local file system, because I use the standart Java classes. However, if the applet is hosted on a tomcat on some server, what is it gonna list - the server's file system, or the client's (that views the applet) file system?

Thanks,
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42644
    
  65
However, if the applet is hosted on a tomcat on some server, what is it gonna list - the server's file system, or the client's (that views the applet) file system?

Unless you make special provisions to access a remote file system (maybe by using a shared network directory), the applet will show local files from the client machine. The applet won't have access to the server-side file system.
Martin Asenov
Ranch Hand

Joined: Aug 05, 2009
Posts: 34
Thank you, Ulf! That was what I was asking for... However, when it comes to upload some files on the server and the applets submit their paths on the client side to the controller, how can I get these files and upload them on the server? By opening a connection?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42644
    
  65
You'd use the Apache Commons HttpClient library in the applet, and the Apache Commons FileUpload library in the servlet. Here's an introductory article that shows how both work together.
ParagS Kulkarni
Ranch Hand

Joined: Oct 04, 2004
Posts: 60
Just a query... does it allow multiple file select?


Thanks, Parag
Martin Asenov
Ranch Hand

Joined: Aug 05, 2009
Posts: 34
Thanks!
Martin Asenov
Ranch Hand

Joined: Aug 05, 2009
Posts: 34
P.S. Another problem occured. I have an MVC architecture, in which the model and the controller are in the jsp context, and the applet that is also shown in the jsp page, and communicates with the M and the C, is executed on the client's machine. I also have an Action class that is supposed to perform any actions that are requested.

To the point. My applet points the files to be uploaded on the server that runs the jsp (gives the paths). Should i form a post method in the same applet and pass it to a background servlet that will perform the action?! Because I don't want to get redirected to another page and stay all the time on the page that displays the applet. At the same time, the applet has different parts that perform monitoring of the output directory (the one on the server), shows log messages and so on, so I have to do it all in the background. Also, I have to use the HTTP protocol.

So , as an overview:

-have an applet that submits to the controller a String[] object that contains absoulte paths to the files to be copied.
-controller and model, which are placed in the jsp context and communicate with the applet. I suppose they're executed on the server machine.
-action class that is supposed to do the action.

Any help on the issue will be greatly appreciated! Thanks in advance!!!

BR,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet accessing client's file system