File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to open a local folder from a html or jsp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to open a local folder from a html or jsp?" Watch "How to open a local folder from a html or jsp?" New topic
Author

How to open a local folder from a html or jsp?

RajKumar Kanakaraj
Greenhorn

Joined: Aug 19, 2013
Posts: 8
Hi Friends,

I would like to know that, Can we open a local folder on the click on a link???
If yes, please share the code :)
d v lokesh venkata
Greenhorn

Joined: Aug 09, 2013
Posts: 16

can you explain your requirement clearly like if you want to open the folder residing at client side or at server side
RajKumar Kanakaraj
Greenhorn

Joined: Aug 19, 2013
Posts: 8
Thanks for a quick reply..:)

I need to open a folder in Server side.

Presently, The application is hosted in local machine.

where should i keep those folders so that i can access from the link.

Thanks for your support.
d v lokesh venkata
Greenhorn

Joined: Aug 09, 2013
Posts: 16

if the folder resides in the project folder in the server then you can get access to that folder using the below statement
File file=new File(request.getRealPath("Folder Name")+"\\"+file_name);
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Backslashes will only work on Windows. Avoid them.

What's the purpose of accessing this file? It's unlikely a File object is necessary.

And, be aware that getRealPath() will not work when an unexpanded war file is used for deployment.

We need more info on how the folders and files are to be used to give appropriate advice.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Raj Chila
Ranch Hand

Joined: Mar 18, 2004
Posts: 128

Suggest also to use properties and refer to this in your code so that it can be easily configured for different environments.
RajKumar Kanakaraj
Greenhorn

Joined: Aug 19, 2013
Posts: 8
Guys, Thanks for the valuable suggestions.

I am developing a webapp using Eclipse IDE.

My ultimate goal is to open a folder on a click on a link (can be a href)

Team can suggest me where to keep the folder and how can i open it from a jsp ?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

It's still not clear what you mean by "open a folder" and whether the file system is on the client or the server.
RajKumar Kanakaraj
Greenhorn

Joined: Aug 19, 2013
Posts: 8

File system is on the server.

File system will be having few documents.

I want to access those documents from the application.

To access those documents i need to open the folder which contains the documents.

Now, I want to access this folder from a jsp..:)

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

If the folders and files are part of the web app, then if (and only if) the web app is not deployed as an unexpanded war file, you can simply use Java file I/O to discovers the files and folders in the controller. The getRealPath() can be used to find the relative paths within the web app.

Collect the information into collections and send to the JSP for display using JSTL and EL.

Li Qiangqiang
Greenhorn

Joined: Aug 21, 2013
Posts: 10
I am in China.so do not mind my poor English.
firstly,i have solved this question before.
there is a way:
1.open Tomcat install folder: ---%TOMCAT_HOME%\conf\server.xml
between :<host> </host> add
2.then start up Tomcat again, interhttp://localhost:8080/FolderTest/1.jsp
you can see , it is done
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to open a local folder from a html or jsp?