I have a JSP page which has an input field with "browse" which when clicked by the user he will choose a file. After that my program will get all the files inside the same directory where the first file (which was previously chosen)is located.
As mentioned earlier I have a JSP page, what I did was I constructed a class which will traverse all the file in that directory. In the class I declared
thinking that from the JSP page, I am expecting to receive a File. However, after traversing through the files I need to populate the filenames or file paths in a table in the same JSP page. So what I did was I declared
in the Action Class. My plan is to convert a File or File array into a List so that after which I will populate it and send it back to the JSP page. My class that suppose to traverse through the files puts the files in a File array.
My problem is that in my traverse class, which has a "main" method, I am receiving a File to be able to get the other contents of the same directory but in my Action Class, I am expecting a File array to be returned by the traverse class. So that I can convert it to a List and then populate it. But I can't do it because my traverse class doesn't return a File array.
Do I need to remove the "main" declaration and change it to a method? Or should I do something else? Hopefully, someone can give me an advice. Thanks.
Originally posted by Darren Alexandria: I have a JSP page which has an input field with "browse" which when clicked by the user he will choose a file. After that my program will get all the files inside the same directory where the first file (which was previously chosen)is located.
Sorry, but a server-side java program such as a Struts Action class simply cannot do that. The <input type=file> tag (or the <html:file> tag) in a JSP can allow a user to browse their local directory and pick one file to upload, which is sent in the form of a binary data stream. Because the Java program resides on the server, it has no visibility at all to the client's file system. It can accept what the client sends it but has no way of browsing the client's directories or looking at its files.
Think about the massive security nightmare that would be if this were possible. Can you imagine every website you ever visited having full access to all the files on your computer?
Now I am enlightened. I am doing this thing for almost 3 months only to find out that it won't work using that way. Now I will start a new one again using applets. No regrets. I have learned a lot of things. =)