• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What to do if you must receive a File then return a File array

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day!

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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?

If you want to write a program that can do the things you've outlined, you must use some sort of client-side technology such as a Java Signed Applet, Flash, or JavaScript.
 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, THANK YOU for the advice.

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. =)

Again, thank you so much!
God bless you.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic