簡體   English   中英

Freemarker 2.3.24自動轉義和spring.ftl宏問題

[英]Freemarker 2.3.24 auto-escape and spring.ftl macros issue

我升級到Freemarker 2.3.24以便使用設置output_format作為HTMLOutputFormat並啟用自動轉義但是當我使用spring.ftl從屬性文件中讀取值時,我得到“使用?html(遺留轉義)時不允許自動-escaping使用標記輸出格式(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),您應該單獨保留全局output_format 相反,您應該僅為非遺留模板指定output_format 這可以通過兩種方式完成。 一種是使用“ftlh”文件擴展名,而不是“FTL”(假設你想HTML轉義),然后設置recognize_standard_file_extensionstrue 另一個是使用template_configurations設置(請參閱http://freemarker.org/docs/pgui_config_templateconfigurations.html )指定一些其他名稱模式以將output_format與(例如與Spring模板不匹配的任何內容)相關聯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM