Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

remote JFileChooser or similar?

 
Andrew Reinartz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have my server-client working the way I want it to so far (just using normal socket-stream communication, not RMI or anything), but I have a question. I'll need to browse some files on the server-side to select one to run some server-side manipulation on. How can I go about this? Is there any way to use JFileChooser remotely (my client-side is Swing based)? Or can I send file arrays from the server to the client that list the current directory say? Any help would greatly appreciated. Thanks,
~Andrew
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi andrewe,

can I send file arrays from the server to the client that list the current directory say?

yes. u can. u can create an Object sort of like,
class FileEntry {
String name;
Vector sublist;
boolean isFile; // file or directory flag
}
name is the name of the FileEntry and the sublist is nothing but the list of sub FileEntry objects.
so its kinda "recursive" object reference u know...
now, u can prepare FileEntry for the directory and it will recursively contain the entries for the all the subdirectories and files and so on...
prepare this object on the server side via some servlet or something and then make the applet-servlet communication via ObjectOutputStream to write this FileEntry object to the applet.
once u get the this big object on applet side u can traverse through it and display it in tree format if you want...
hope this helps..
regards
maulin
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oft-repeated Caveat: a WEB server is NOT a FILE server!
IFF your web server box ALSO has file-serving software on it (Samba, Windows Networking, NFS, etc.) THEN you can browse network shares courtesy of the FILE server software, but not otherwise.
Or, if you can see the server files in Windows Notepad file browser (for example), then you can see the files using the Swing file browser. But your web client and server (or lack thereof) have nothing to do with the process.
You can program part of a webapp to act like it's a miniature file server by writing suitable server-side code. The apparent file serving abilities that many web servers seem to have (sometimes by default) is illusory. They aren't giving you access to the file - in fact, HTTP has no such abilities. They're making a copy of the file and sending it to you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic