aspose file tools*
The moose likes JSP and the fly likes Opening a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Opening a file" Watch "Opening a file" New topic
Author

Opening a file

sreedhar Lackka
Ranch Hand

Joined: Jul 05, 2008
Posts: 154
Hi All,

Thanks in advance.

I have uploaded a file to application server's shared folder and the path for the same is some thing like "opt/webapps/myFile.txt".
I want to view/open this file from my JSP page browser, Please help me how to do it??


Regards,
Sree
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30894
    
158

That should be done in Java code and not a JSP. A Servlet would read the file and stream it to the user. Note that the servlet shouldn't accept the whole path of the file as that would be a security risk.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sreedhar Lackka
Ranch Hand

Joined: Jul 05, 2008
Posts: 154
Thanks a lot for your reply.
Could you please give me any example code?
dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 98
Hi Sreedhar,

My thoughts!!!
You can try using the java.util.Scanner to access the txt/* ,and get the result into java.util.List and redirect to JSP and display the result using JSTL tags.


Alternately,
You can place this code in some .java file and call it by a servlet and display in jsp
Pawan Kr Gupta
Greenhorn

Joined: Nov 21, 2010
Posts: 26
Please use this code to download the .txt file

sreedhar Lackka
Ranch Hand

Joined: Jul 05, 2008
Posts: 154
Thanks a lot for your help.

I am able to access and open the file which is of any type but the code is working only for local files. i.e., If I create a folder in my local machine and put some file there and can able open the same file.
Howerver, I am unable to open the file which stored in Appserver's NAS link.. I am giving the file path as /opt/...../x.txt, still unable to open the file I am getting 404 error.

please advice
Pawan Kr Gupta
Greenhorn

Joined: Nov 21, 2010
Posts: 26
do one things.Provide the sharable functionality to opt folder , then it will work 100%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Opening a file