JSF 2和文件系统链接 [英] JSF 2 and a link to file system

查看:101
本文介绍了JSF 2和文件系统链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要提供指向服务器文件系统中文件的链接.在纯HTML中,是这样的:

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>

但是我似乎无法在JSF 2上使用这个简单的东西.我像这样尝试了h:outputLink:

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>

但是当我单击链接时,没有任何反应. (我尝试使用Windows和Unix样式分隔符,并且还在路径之前添加了file:///,但没有运气.)

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.)

h:commandLink和普通的h:link也会发生同样的情况,如果我理解正确的话,无论如何,它们都适合在JSF页面之间导航. (是的,尽管这没有什么意义,我还是试图将它们放在一种形式中.)

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?

推荐答案

您也可以在JSF中使用<a>.

You can in JSF also just use <a>.

但是这行不通.您是否知道此链接将指向客户端本地磁盘文件系统上的资源,而不是服务器本地磁盘文件系统上的资源? HTML在Web浏览器(而不是Web服务器)中运行".换句话说,您网页的每个访问者都必须在其本地磁盘文件系统上拥有该文件已经.另外,出于安全原因,大多数浏览器禁止在网页本身通过http://提供服务时打开file://资源.

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://.

如果要从外部公共Web内容中提供内容,则必须为其创建一个新的webapp上下文或自定义文件servlet.

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.

这篇关于JSF 2和文件系统链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆