I need to create a list of links on my JSP, related to some files that are in a specific folder (with html extension), on a Unix server. My questions are: How do I "connect" to the Unix server? My JSP will be stored on the same server that I need to search into. What method I should use to search through my specific folder?
2 Answers
You can use the File.listFiles(...) method (on any OS/filesystem actually). Be aware that there might be limitations if the uid
for webserver has no access to the folder/files or is eg. in a chroot'ed environment on the UNIX box.
The following code snippet
File[] files = new File( "/your/folder" ).listFiles( "*.html" );
should give you a File[]
array with the files satisfying the .html condition in /your/folder.
Cheers,

- 15,729
- 10
- 59
- 55
-
Thank you for your suggestion. And I don't need to "connect" in any way to my server? Sorry but I'm new on Unix. – abierto Dec 21 '12 at 08:56
-
1Provided that the JSP is running in a servlet container on the UNIX server, there is no need to "connect", no. – Anders R. Bystrup Dec 21 '12 at 08:58
-
I've also found something similar to my problem. What's the difference between what you posted and [this](http://stackoverflow.com/questions/5601622/java-swing-combobox-list-of-files-from-unix-machine)? – abierto Dec 21 '12 at 09:25
You could do this in several ways.
If the share on the server is local or locally mounted already, then you can use Anders R.Bystrups answer.
If it is not, then you need some method of connecting to the server.
If it is a shared resource (a shared folder, for example), then you can access it with //server/share/file).
If the server is running FTP or SFTP, then you can use the relevant service to retrieve the list of files.
Finally, the server could run a web service (which you would have to write) which could expose the list of files it has.

- 44,755
- 24
- 88
- 123