1
  1. I need a code for how to browse for folder (not file) using JSP and Javascript.
  2. I looked for the JAVA code for browse for folder using JFileChooser library but I want the default window to be opened (which opens in browse for file).
  3. I'm developing a webapp which will scan the folder based on the path and will generate the output.

Thanks in advance.

Prakash K
  • 11,669
  • 6
  • 51
  • 109
Pankaj
  • 592
  • 7
  • 19
  • 1
    U mean you want to scan the file-system of the User who is accessing your web-app through a browser? If that is the case, then any usecase why would u want to do such a thing? – Prakash K Apr 17 '13 at 09:36
  • It's not for the user it is for the administrators who will scan the csv file present in the particular folder to check the integrity..If u know please give answer. – Pankaj Apr 17 '13 at 10:14
  • *csv file present in the particular folder*, is this folder on the server on which your web-app is running? – Prakash K Apr 17 '13 at 13:34

1 Answers1

1

1.I need a code for how to browse for folder (not file) using JSP and Javascript.

Javascript does not have access to the file-system due to security reasons, as this answer says and also this answer.

So you would have to use flash or java applet as suggested in this answer or else you would have to wait till the time HTML5 File API matures :-)

But, if your requirement is that your a User (may be with administrator rights in the application) logins to the web-application through a web-browser and wants to scan (view the contents of) the particular folder on the server side (where the web-app is deployed and not the file system on his own machine) then you can use the suggestion given in this answer, just to elaborate on this:

  1. Have a <form> which will have a text-box (to take the folder name or full-path) in the JSP, on submit of this form a request will be sent to the server.
  2. The response would be list of files (List<String>) in that particular folder passed through the request.
  3. you can also submit the request through ajax in which case you would return a JSONArray as suggested.
  4. Now on the Server it would be normal Java File API stuff to fetch all the files in the folder you get from the request.

Sorry to say this but I don't think you would get a ready-made code to do what you want and that is not how things work on SO.

2.I looked for the JAVA code for browse for folder using JFileChooser library

You said you are building a web-app right? JFileChooser is a Swing component and as far as I know cannot be used in JSP to achieve what you desire.

3.I'm developing a webapp which will scan the folder based on the path and will generate the output.

The steps are explained in point (1).

Hope this helps and gives relevant hint and direction to go forward.

Community
  • 1
  • 1
Prakash K
  • 11,669
  • 6
  • 51
  • 109
  • I've got the answer for this by the way...call the AJAX Post method which will call another JSP file..and in a JSP file create the object of Java file.The java file consists of a Swing component which will fetch the browse for folder link and will set the value in one variable.Access the variable and put out.println(variable) and out.flush() in JSP file.This will return the path to the calling JSP file. – Pankaj May 28 '13 at 05:16
  • @Pankaj Gr8! to hear that. Can you put some code example to explain your approach? You can provide the explanation as an answer to your own question and then accept it, so that it would help fellow members. Thanks – Prakash K May 28 '13 at 05:28