从零学习freemarker(5)Include的使用
来源:互联网 发布:mac 命令行新建文件夹 编辑:程序博客网 时间:2024/05/21 22:37
http://www.java2000.net/p7861
模板
TestInclude.copyright.html
输出结果
<script type="text/javascript"><!--google_ad_client = "pub-2908059660288034";/* 728x90,首页中间 创建于 08-8-14 */google_ad_slot = "5903610560";google_ad_width = 728;google_ad_height = 90;//--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
Include的使用
代码- package freemarker;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.OutputStreamWriter;
- import java.io.Writer;
- import java.util.HashMap;
- import java.util.Map;
- import freemarker.template.Configuration;
- import freemarker.template.Template;
- public class TestInclude {
- private Configuration cfg;
- public Configuration getCfg() {
- return cfg;
- }
- public void init() throws Exception {
- cfg = new Configuration();
- cfg.setDirectoryForTemplateLoading(new File("bin/freemaker"));
- }
- public static void main(String[] args) throws Exception {
- TestInclude obj = new TestInclude();
- obj.init();
- Map root = new HashMap();
- Template t = obj.getCfg().getTemplate("TestInclude.ftl");
- Writer out = new OutputStreamWriter(new FileOutputStream("TestInclude.html"), "GBK");
- t.process(root, out);
- System.out.println("Successfull................");
- }
- }
- <html>
- <head>
- <title>Test page</title>
- </head>
- <body>
- <h1>Test page</h1>
- <p>Blah blah...
- <#include "/TestInclude.copyright.html">
- </body>
- </html>
- <hr>
- <i> Copyright (c) 2007-2008 <a href="http://www.java2000.net">JAVA世纪网</a>, <br>
- 版权所有. </i>
- <html>
- <head>
- <title>Test page</title>
- </head>
- <body>
- <h1>Test page</h1>
- <p>Blah blah...
- <hr>
- <i> Copyright (c) 2007-2008 <a href="http://www.java2000.net">JAVA世纪网</a>, <br>
- 版权所有. </i>
- </body>
- </html>
<script type="text/javascript"><!--google_ad_client = "pub-2908059660288034";/* 728x90,首页中间 创建于 08-8-14 */google_ad_slot = "5903610560";google_ad_width = 728;google_ad_height = 90;//--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 从零学习freemarker(5)Include的使用
- 从零学习freemarker(3)IF语句的使用
- 从零学习freemarker(4)&amp;lt;#list 的使用
- 从零学习QT Designer 的使用
- 从零学习freemarker(1)老紫竹的第一个freemaker程序
- 从零学习freemarker(2)给模板传递参数的测试
- freemarker include与import的区别, 宏marco的使用
- SpringBoot+Freemarker 项目ftl中使用include的异常
- 从零学习Swift<5>
- springmvc整合freemarker时,freemarker使用include的根路径的问题
- freemarker的学习和使用
- Android--从零单排系列(5)--常用传感器的使用
- 从零学习github
- 从零学习嵌入式
- 从零 使用vc
- 关于freemarker include文件路径的问题
- 关于freemarker include文件路径的问题
- freemarker 的 include指令,引入另一个页面
- 从零学习freemarker(1)老紫竹的第一个freemaker程序
- PHP字符串经典函数
- 从零学习freemarker(2)给模板传递参数的测试
- 从零学习freemarker(3)IF语句的使用
- 从零学习freemarker(4)&amp;lt;#list 的使用
- 从零学习freemarker(5)Include的使用
- 变量的使用
- 关于PHP重定向
- ws_download
- 获取浏览器和操作系统函数
- php 生成各种文件格式
- 数据库封装
- SQL Server 2000启动1069错误解决方法
- 无法附加。绑定句柄无效