【问题标题】:Freemarker 2.3.24 auto-escape and spring.ftl macros issueFreemarker 2.3.24 自动转义和 spring.ftl 宏问题
【发布时间】:2016-05-18 11:37:34
【问题描述】:

我升级到 Freemarker 2.3.24 以便使用设置 output_format 作为 HTMLOutputFormat 并启用自动转义,但是当我使用 spring.ftl 从属性文件中读取值时,我得到“使用 ?html(传统转义)不是当使用标记输出格式 (HTML) 启用自动转义时允许,以避免双重转义错误。”有谁知道如何将 Freemarker 自动转义与 spring 属性文件阅读器集成?

这是我的配置 bean:

<bean id="freeMarkerConfigurer"
      class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="/WEB-INF/views/"/>
    <property name="defaultEncoding" value="UTF-8"/>
    <property name="freemarkerSettings">
        <props>
            <prop key="output_format">HTMLOutputFormat</prop>
        </props>
    </property>
</bean>

这是我的 test.ftl

<#import "/spring.ftl" as spring/>
<html>
<div>hello</div>
<p><@spring.message "welcome"/></p>
</html>

我得到这个错误:

Using ?html (legacy escaping) is not allowed when auto-escaping is on with a markup output format (HTML), to avoid double-escaping mistakes.

【问题讨论】:

    标签: spring freemarker


    【解决方案1】:

    由于您有一些“遗留”模板(来自 Spring),因此您应该不理会全局 output_format。相反,您应该只为非旧模板指定output_format。这可以通过两种方式完成。一种是使用“ftlh”文件扩展名而不是“ftl”(假设您想要 HTML 转义),然后将 recognize_standard_file_extensions 设置为 true。另一种是使用template_configurations 设置(请参阅http://freemarker.org/docs/pgui_config_templateconfigurations.html)指定一些其他名称模式以将output_format 与(例如与Spring 模板不匹配的任何内容)相关联。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-25
      • 2012-01-17
      • 2020-01-17
      • 2010-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      相关资源
      最近更新 更多