http://www.java2000.net/p7861
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>
TestInclude.copyright.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">
</script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script>
分享到:
相关推荐
总结,本教程将带领读者从零开始,逐步掌握使用JSP构建电子商务应用的全过程,从基本概念到高级技巧,从设计用户界面到实现业务逻辑,再到性能优化和安全防范,全面涵盖JSP在电商系统中的应用。通过阅读提供的PDF...
通过以上内容的学习,你可以从零开始,逐步建立起对JSP的深入理解,并能独立完成小规模的Web项目。同时,随着经验的积累,你还可以进一步探索更高级的Web开发技术和架构模式,提升自己的专业技能。
书中概念清晰、环环相扣,便于读者高效地学习。《深入浅出Struts2》适合Java Web 程序员阅读和参考,也可以作为计算机相关专业教材。 编辑推荐 《深入浅出Struts2》是广受赞誉的Struts2优秀教程.它全面而深入地...
如果不需要 Actuator 的安全性,可以通过配置属性 `management.endpoints.web.exposure.include=*` 和 `management.endpoints.web.exposure.exclude=*` 来控制暴露哪些端点。 **4.3 我们如何监视所有 Spring Boot ...