Tomcat WebDAV强制下载

Tomcat WebDAV force download

我有一个部署了 WebDAV servlet 的 tomcat 网络服务器。我有可通过 WebDAV 访问的多媒体文件,并希望在通过浏览器访问时强制下载它们,而不是允许浏览器从服务器流式传输它们。我该怎么做?

您需要配置 Content-Disposition header 字段。

If the disposition type matches "attachment" (case-insensitively), this indicates that the recipient should prompt the user to save the response locally, rather than process it normally (as per its media type).¶

On the other hand, if it matches "inline" (case-insensitively), this implies default processing. Therefore, the disposition type "inline" is only useful when it is augmented with additional parameters, such as the filename (see below).

Reference

我解决了我的问题。我写了一个过滤器来将所有请求发送到 WebDAV servlet,除非它是一个多媒体文件 chrome 会尝试播放。在那种情况下,请求将被发送到一个自定义 servlet,该 servlet 将设置 Content-Disposition header,然后将文件数据写入 response.getOutputStream()