在使用freemarker过程中,需要include或者import其他ftl文件或者html文件,这个导入文件的路径,经常会出错。
导入文件的路径与程序中设置的路径有关
@Override
public void init() throws ServletException {
cfg = new Configuration();
cfg.setServletContextForTemplateLoading(getServletContext(), "WEB-INF/templates");
}
如上,设置的路径是:"WEB-INF/templates",因此,在后面的模板中import或者include的路径是相对于"WEB-INF/templates"的。