81,092
社区成员
发帖
与我相关
我的任务
分享
public class createStaticHTML {
private static Configuration freemarkerCfg = new Configuration();
static{
freemarkerCfg.setServletContextForTemplateLoading(ServletActionContext.getServletContext(), "/WEB-INF/template");
freemarkerCfg.setEncoding(Locale.getDefault(), "utf-8");
freemarkerCfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
}
public static void createHTML(Map<String,Object> sourcedata,String templatePath,String targetHtmlPath) throws IOException, TemplateException{
try{
Template template = freemarkerCfg.getTemplate(templatePath,"utf-8");
template.setEncoding("utf-8");
String htmlPath = ServletActionContext.getServletContext().getRealPath("/")+targetHtmlPath;
File htmlFile = new File(htmlPath);
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile), "utf-8"));
template.process(sourcedata, out);
out.flush();
out.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}
public class WelcomeCurtainAction extends ActionSupport {
//private String returnhtmlpath;
@Override
public String execute() throws Exception{
Map<String,Object> MoodTextData = new HashMap<String,Object>();
TextData.put("title", "aaaaaaaaaaaaa");
TextData.put("context", "bbbbbbbbbbbbbbbbbbbbbbbbb");
//String htmlpath = "testhtml.html";
createStaticHTML.createHTML(TextData,"testhtml.ftl", "testhtml.html");
//this.returnhtmlpath=htmlpath;
return SUCCESS;
}
<div id="XXXXX_feature">
<div id="feature_left">
<h1>${TextData.title}</h1>
<p>${TextData.context}</p>
</div>
</div>