/* -----------test.java---------- */
package auh.action;
import java.util.HashMap;
import java.util.Map;
import auh.server.MakeFile;
import com.opensymphony.xwork2.ActionSupport;
public class test extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
Map<String,Object> root = new HashMap<String,Object>();
String name="xujianke";
root.put("book", name);
MakeFile make=new MakeFile();
make.geneHtmlFile("book.ftl", root,"/test", "index.html");
System.out.println(make.getSRootDir());
return SUCCESS;
}
}
/* ------book.ftl (这个文件放在web根目录下的/WEB-INF/template)----- */
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Hello World</title>
</head>
<body>
${book}<br>哈哈
</body>
</html>
本文介绍了一个简单的示例,展示了如何使用Freemarker模板引擎与Java集成来生成HTML页面。通过创建一个Java类继承ActionSupport,并在execute方法中准备数据,然后调用MakeFile类的geneHtmlFile方法生成包含这些数据的HTML文件。
1526

被折叠的 条评论
为什么被折叠?



