JSF 2 and a link to file system

走远了吗. 提交于 2019-12-11 09:08:38

问题


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?


回答1:


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

  • Reliable data serving


来源:https://stackoverflow.com/questions/8435574/jsf-2-and-a-link-to-file-system

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!