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.
gunacesunAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CEHJConnect With a Mentor Commented:
Well it looks like something might be altering it later then. Try this first

url = url.replaceAll("^file:////", "file:/");
0
 
CEHJCommented:
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
 
gunacesunAuthor Commented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
objectsCommented:
> , 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
 
CEHJCommented:
>>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
 
gunacesunAuthor Commented:
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
 
CEHJCommented:
Please post your code
0
 
gunacesunAuthor Commented:
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
 
CEHJCommented:
Could you possibly post some examples of what

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

returns?
0
 
gunacesunAuthor Commented:
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
 
CEHJCommented:
So you're saying that those don't work as links?
0
 
gunacesunAuthor Commented:
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
 
objectsConnect With a Mentor Commented:
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
 
gunacesunAuthor Commented:
Thanks to both CEHJ and objects for your time.
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.