【问题标题】:Include html file uploaded by user包含用户上传的html文件
【发布时间】:2016-12-27 14:36:06
【问题描述】:

这就是我想做的事情:用户上传一堆 html 文件作为 zip 存档。我解压缩该存档并在网站上显示 html 内容。

为此,我想将 html 内容包含到 thymeleaf 页面中。到目前为止我已经尝试过了:

<div th:include="http://localhost:8181/MySpringApp/uploads/include.html"></div>
<div th:include="@{/uploads/include.html}"></div>
<div th:include="@{~/uploads/include.html}"></div>

在所有三种情况下,我都会收到以下错误(URL 不同):

Exception processing template "dashboard": Error resolving template "/uploads/include.html", template might not exist or might not be accessible by any of the configured Template Resolvers (dashboard:40)

我怎样才能让它发挥作用?我只看到了包含 template 文件夹中的静态文件的示例。但这不是我想做的。

我正在使用 Wildfly 9,并在 standalone/data 文件夹中创建了 uploads 文件夹。

【问题讨论】:

    标签: java spring-boot thymeleaf wildfly-9


    【解决方案1】:

    这样的代码应该可以工作:

    <div th:include="@{/uploads/include}"></div>
    

    【讨论】:

      【解决方案2】:

      这可能是许可问题吗?我只是想知道,因为您说某些外部用户可以上传这些文件,所以您可能没有正确的权限来显示或使用它们。

      希望对你有帮助!

      【讨论】:

        【解决方案3】:

        假设您的uploads 文件夹位于templates 下,请将 HTML 插入为:

        <div th:insert="~{uploads/include}"></div>
        

        顺便说一句,自 Thymeleaf 3.0 起不推荐使用th:include

        【讨论】:

          猜你喜欢
          • 2019-10-17
          • 1970-01-01
          • 2012-11-21
          • 2014-09-06
          • 2010-11-16
          • 2015-10-09
          • 2017-05-18
          • 2011-06-19
          • 2013-06-01
          相关资源
          最近更新 更多