日期:2014-05-17  浏览次数:20590 次

FreeMarker 生成静态html(举例)

/* -----------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>
 
?

?