jQuery in Action, 2nd edition*
The moose likes HTML, CSS and JavaScript and the fly likes To open file by passing file path which having spaces is showing path wrong. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "To open file by passing file path which having spaces is showing path wrong." Watch "To open file by passing file path which having spaces is showing path wrong." New topic
Author

To open file by passing file path which having spaces is showing path wrong.

SaiManasa Dasari
Ranch Hand

Joined: Aug 21, 2012
Posts: 32
Hi All,
here is my code to open file by clicking on filename link in jsp using javascript.



javascript function is::;



filepath is../home/infrastructure/WEB-INF/classes/attachments_email/4091/Upload Document/Consolidate.pdf
But problem is in filepath spaces are there at "Upload Document".when clicking on this link the path showing like
"/home/infrastructure/WEB-INF/classes/attachments_email/4091/Upload%20Document/Consolidate.pdf" in firefox and chromium browsers..

please can anyone help me on this and i want only to open file directly by clicking on filename.is this code works for that or need any changes?please help me.

THANKS...
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Sai,

You need to encode your string. there is a function escape and unescape in Java script which will you can utilize for encoding the path.

Link for the reference.
http://www.w3schools.com/jsref/jsref_unescape.asp

Regards
Jatan

SaiManasa Dasari
Ranch Hand

Joined: Aug 21, 2012
Posts: 32
Hi
Thanks for Your replies..I tried unescape() as

window.open(unescape(filepath)).

But still it tring to open the path like replacing space with %20 when clicking on the link..please can anyone help me.

Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

%20 is the correct encoding for a space character.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
SaiManasa Dasari
Ranch Hand

Joined: Aug 21, 2012
Posts: 32
Thanks for Your reply.

But while opening it is showing an error like http status404 error as the requested resource not available.but my pdf file iss there in that specified path..please reply me what to do to get open that file by clicking on that link.please help me.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

What is the actual URL that is being used and what is the exact file path and file name for the PDF? Not giving us the details will simply result in a delay in getting an answer.
SaiManasa Dasari
Ranch Hand

Joined: Aug 21, 2012
Posts: 32
Thanks for Your Replies..I got solution for my problem using servlets and jsp posting in javaranch forums....

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To open file by passing file path which having spaces is showing path wrong.