• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Opening a file

 
sreedhar Lackka
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sreedhar Lackka
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your reply.
Could you please give me any example code?
 
dileep keely
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use this code to download the .txt file

 
sreedhar Lackka
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do one things.Provide the sharable functionality to opt folder , then it will work 100%
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic