1

I need to provide a link to a file in the server's filesystem. In plain HTML something like this does it:

<a href="C:\Users\user\resources\147ebg.jpg">Image or word doc or whatever</a>

But I can't seem to get this simple thing working with JSF 2. I tried h:outputLink like this:

<h:outputLink value="C:\Users\e\workspace\IDEXRoughAuctions\WebContent\resources\147ebg.jpg" id="test1">Testing output link</h:outputLink>

but when I click on the link nothing happens. (I tried windows and unix style separators, and also prepending file:/// before the path, with no luck.)

The same happens with h:commandLink, and just plain h:link, which are anyway geared, if I understand correctly, towards navigating between JSF pages. (And yes, I tried to put them in a form, although that makes little sense.)

So how is this simple task done?

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
Herzog
  • 923
  • 1
  • 14
  • 28

1 Answers1

2

You can in JSF also just use <a>.

But this isn't going to work. Do you realize that this link would point to a resource on client's local disk file system and not on the server's local disk file system? HTML "runs" in webbrowser, not webserver. In other words, every visitor of your webpage must have that file already on its local disk file system. Also, most browsers prohibit due to security reasons opening file:// resources when the webpage is by itself served over http://.

If you want to serve content from outside public web content, then you've got to create a new webapp context or a custom file servlet for it.

See also

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555