有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java包含不解析模板文件

我有三个非常简单的文件:

main。ftl

<#include "header.ftl">

<h1>Test</h1>

<#include "footer.ftl">

标题。ftl

<h1>Header</h1>

页脚。ftl

<h1>Footer</h1>

从技术上讲,它应该输出三个h1,但我的实际输出是:

  1. 我读到,根据ftl的配置,括号可能会从<>更改为[],我尝试过更改,但仍然没有更改
  2. 我使用了*通配符来检查父目录和当前目录,但仍然不走运
  3. Freemarker文档声明默认情况下include 指令将内容解析为.ftl文件,因此我应该没有 问题:

parse: If it is true, then the included file will be parsed as FTL, otherwise the whole file will be considered as simple text (i.e, no FreeMarker constructs will be searched in it). If you omit this option, then it defaults to true.

那么为什么我的模板没有被解析呢


共 (3) 个答案

  1. # 1 楼答案

    事实证明,Freemarker没有将.ftl文件作为实际的.ftl文件进行处理,因为服务器正在将内容呈现为.jsp文件,以修复我的更改:

    <view-map name="frs" page="">
    

    为了

    <view-map name="frs" type="screen" page="component://ecommerce/widget/CommonScreens.xml#your-identifier"/>
    

    修复了渲染。默认情况下,如果未定义type属性,则会自动将其呈现为JSP文件

  2. # 2 楼答案

    here

    <#include "/common/copyright.ftl">
    

    所以我假设页脚和页眉与主文件在同一个文件夹中。所以你必须做一些事情,比如:

    <#include "*/header.ftl">
    <#include "*/footer.ftl">
    
  3. # 3 楼答案

    为了未来的读者。。。#include指令从未像<#include ...>那样输出自身(因此,正如您现在知道的,它是main.ftl未传递给FreeMarker的)。它的parse参数适用于included文件。此外,如果找不到模板,它将抛出异常,不会执行诸如打印<#include ...>之类的任意操作