Link to home
Start Free TrialLog in
Avatar of gunacesun
gunacesun

asked on

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

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.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of gunacesun
gunacesun

ASKER

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.
> , I used the File.toURI method since File.toURL has been deprecated.

Thats corect, don't use toURL

How exactlky are you using it?

>>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()
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.
Please post your code
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>";
Could you possibly post some examples of what

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

returns?
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
So you're saying that those don't work as links?
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.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks to both CEHJ and objects for your time.
:-)