[英]Configuring auto_escape in freemarker spring-mvc Application
我正在使用帶有freemarker-2.3.27-incubating.jar
spring-mvc。 以及如下所示的視圖解析器的bean配置...
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/"/>
<property name="freemarkerSettings">
<props>
<prop key="template_exception_handler">rethrow</prop>
<prop key="number_format">0.########</prop>
<prop key="date_format">dd/MM/yyyy</prop>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="suffix" value=".ftl"/>
<property name="exposeSpringMacroHelpers" value="true"/>
<property name="exposeRequestAttributes" value="true"/>
<property name="exposeSessionAttributes" value="true"/>
<property name="requestContextAttribute" value="rc"/>
</bean>
我在哪里以及如何使用<#ftl output_format="HTML">
或<#ftl output_format="HTML" auto_esc=true>
啟用HTML auto-scape
?
您只需在模板文件本身的開頭添加#ftl
標簽。 但我會建議設置recognize_standard_file_extensions
到true
的freemarkerSettings
屬性,然后使用.ftlh
文件擴展名,而不是.ftl
。 或者,甚至更好,你設置incompatible_improvements
到2.3.27
有代替,這使得recognize_standard_file_extensions
和一些修正。 (同樣重要的是,如果出於某種原因需要.ftl
,也可以在freemarkerSettings
屬性中將output_format
設置為HTMLOutputFormat
。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.