简体   繁体   English

在freemarker spring-mvc应用程序中配置auto_escape

[英]Configuring auto_escape in freemarker spring-mvc Application

I am using spring-mvc with freemarker-2.3.27-incubating.jar . 我正在使用带有freemarker-2.3.27-incubating.jar spring-mvc。 And bean configuration for view-resolver like below... 以及如下所示的视图解析器的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>

Where and how can I use <#ftl output_format="HTML"> or <#ftl output_format="HTML" auto_esc=true> to enable HTML auto-scape ? 我在哪里以及如何使用<#ftl output_format="HTML"><#ftl output_format="HTML" auto_esc=true>启用HTML auto-scape

The #ftl tags you just add at the beginning of the template files themselves. 您只需在模板文件本身的开头添加#ftl标签。 But I would recommend setting recognize_standard_file_extensions to true in the freemarkerSettings properties, and then use .ftlh file extension instead of .ftl . 但我会建议设置recognize_standard_file_extensionstruefreemarkerSettings属性,然后使用.ftlh文件扩展名,而不是.ftl Or, even better, you set incompatible_improvements to 2.3.27 there instead, which enables recognize_standard_file_extensions and some fixes. 或者,甚至更好,你设置incompatible_improvements2.3.27有代替,这使得recognize_standard_file_extensions和一些修正。 (Last not least, in case you want this for .ftl for some reason, you can set output_format to HTMLOutputFormat in freemarkerSettings properties too.) (同样重要的是,如果出于某种原因需要.ftl ,也可以在freemarkerSettings属性中将output_format设置为HTMLOutputFormat 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM