?
Solved

How do I access a PDF file on the Unix server from my browser running on Windows XP

Posted on 2008-06-18
15
Medium Priority
?
185 Views
Last Modified: 2013-11-05
I display the name of the file on the browser and when the user clicks on the name, I want to display the file.

What I've tried:
I have created a URI from a Java File object. The URI looks like \\\\comp1\public\test\2008\06\file1.PDF (It only has 4 \'s at the beginning of the URI). When I click on the link nothing happens. If the URI has 5 \'s in the beginning it works.

How do I fix this?

Or is there a better/differnt way to do this?

TIA,
Ganesh.
0
Comment
Question by:gunacesun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 21817113
That's not a path that should be in a browser really - it's a UNC path.

Try using File.toURL and use the URL
0
 

Author Comment

by:gunacesun
ID: 21818024
Thanks for the reply CEHJ.

But when I said "I have created a URI from a Java File object." in my original post, I used the File.toURI method since File.toURL has been deprecated.
0
 
LVL 92

Expert Comment

by:objects
ID: 21818373
> , I used the File.toURI method since File.toURL has been deprecated.

Thats corect, don't use toURL

How exactlky are you using it?

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 21820017
>>I used the File.toURI method since File.toURL has been deprecated.

Yes, sorry - forgot about that. In that case you can do

file.toURI().toURL()
0
 

Author Comment

by:gunacesun
ID: 21821497
CEHJ:

I've already tried file.toURI().toURL(), and the value returned is same as file.toURI().

objects:

I have a File object and I get the uri by using the method File.toURI(). Hope this answers your question.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21821581
Please post your code
0
 

Author Comment

by:gunacesun
ID: 21821617
Here is the code snippet:

      File file = (File) getCurrentRowObject();

        URI uri = null;
        URL url = null;

        uri = file.toURI();
        try {
              url = uri.toURL();
        } catch (MalformedURLException e) {
              e.printStackTrace();
        }
        System.out.println("uri: " + uri);
        System.out.println("url: " + url);
       
        return "<a href=" + url + " >Open file</a>";
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21821970
Could you possibly post some examples of what

  System.out.println("url: " + url);

returns?
0
 

Author Comment

by:gunacesun
ID: 21822077
Here are the sysout msgs:

uri: file:////Comp1/Public/Test%20Scan%20Sent%20Image/2008/06/file-1.PDF
url: file:////Comp1/Public/Test%20Scan%20Sent%20Image/2008/06/file-1.PDF
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21822246
So you're saying that those don't work as links?
0
 

Author Comment

by:gunacesun
ID: 21822488
Yes.

When I try to manually open the file from the browser, I notice that the URI has 5/'s after "file:", but the URI or URL returned by the program has only 4 /'s. When I click on the program generated url/uri, nothing happens.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 600 total points
ID: 21822758
Well it looks like something might be altering it later then. Try this first

url = url.replaceAll("^file:////", "file:/");
0
 
LVL 92

Assisted Solution

by:objects
objects earned 200 total points
ID: 21827329
also print out the file path to check it is correct.

also those url's are onl;y going to work if your browser is running on the same machine that the files are on. If its a different box then you'll need a different technique, such as a download servlet

> When I try to manually open the file from the browser, I notice that the URI has 5/'s after "file:", but the URI or URL returned by the program has only 4 /'s. When I click on the program generated url/uri, nothing happens.

It should only actually have 3

0
 

Author Closing Comment

by:gunacesun
ID: 31468574
Thanks to both CEHJ and objects for your time.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21830245
:-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question