We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

how can I build a URL in JSP page ?

Alaska Cowboy
on
Medium Priority
1,216 Views
Last Modified: 2012-05-11
I need to build a link in a JSP page that looks (in effect) like this
<a href="file:///T:/Operations/IT/IT Shared/Enterprise/EDW/EDW/cdr_reports/ods_cdr_tab_cnt_035_2011_04_26_at_10_33.out">CDR Load</a>

So it's pulling up a file from the corporate file system

The destination and the link text are both data returned from Oracle.

I tried it like this and the URL is formed ok, looks like a link, but when I click it nothing happens.

      <td align="left"><a href="<c:out value="${hist.cdrReportLoc}"/>"><c:out value="${hist.procDescription}"/></a></td>

With the above command the link looks ok, it comes out as
file:///T:/Operations/IT/IT Shared/Enterprise/EDW/EDW/cdr_reports/ods_cdr_tab_cnt_035_2011_04_26_at_10_33.out

but when I do this is straight HTML, the link opens ok
<a href="file:///T:/Operations/IT/IT Shared/Enterprise/EDW/EDW/cdr_reports/ods_cdr_tab_cnt_035_2011_04_26_at_10_33.out">T drive, April 2011</a>

So something with JSP or JSTL I'm not handling correctly.
Comment
Watch Question

Commented:
I believe, as you are trying to access a file on local file system, browser wont allow that access, if the html was served from server.

Because jsp's are served from server, browser is blocking the access to files.

When you open html file from the same machine, where the file being accessed exists, then browser allows because it knows that html was accessed from the same machine, and allows access to local file system.

To get this done through jsp's, you need to send a separate request to your servlet, and download the file.

Author

Commented:
cmalakar,

ok, thanks for the quick reply. So . . . how do I send a separate request to my servlet to download the file ? (I don't know anything about servlets, so if I have one, I wasn't aware of it . . . )

Author

Commented:
I am having issues between browsers, I got the link to be as accurate as I can get for now. It works on IE-7 but not on FF-4.0 or Chrome 10.0
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Awarded 2011
Awarded 2011

Commented:
One way to do it - if the file is located on your corporate file share, then you check if you can make a link in
somewhere under document root of your server which would lead you to
to the location of the file. Then you could have the path to your file
starting with http://  rather tyhan with file:// and this issue about some browsers having possible
limitaions for the file: protocol in the HTML page, downloaded from server, will go away.

Author

Commented:
unfortunately, I cannot put the documents in the root of my server, it has to be off onto a corporate shared windows directory. Thanks.
Awarded 2011
Awarded 2011

Commented:
You don't need to put the documents there - documents can suit wehere they are;
the only thing you need is to create link to the folder or to upper folder, under which
the documents are sitting

Author

Commented:
but the documents aren't on a web server, so how do I create the link ? I thought only the file:///... would work.
Awarded 2011
Awarded 2011

Commented:
well usually all servers on one corporate site (at least so it is on all sites in our company)
 are accessed form one another as remote network
folders. That was my assumption that location with the documents is accessible as
network folder from the web server. If that is not the case, then it complicates the situation

Author

Commented:
it's just a file server, not a web server. I think I will have to write a servlet, if only I knew how.
Awarded 2011
Awarded 2011

Commented:
Is your file server a windows machine?
Or is ait accessible form windows?
If so, it takes just a 15 minutes to set up
a web server on windows machine (Apache)
and then you can use the http: link instead of file:
to your documents

Author

Commented:
>>Is your file server a windows machine?
yes

but I won't be able to set up apache, this is a corporate environment and everything is locked down.
Awarded 2011
Awarded 2011

Commented:
Well, if you don't have admin privileges on any windows machine, then
you cant do it - true.

Author

Commented:
see new question
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.