/**
*按模板文件生成页面字符串。
*@paramcontext
*@paramdata数据映射对象。
*@paramtemplatePath模板文件的路径,和struts配置文件里的相同。
*@return
*/
privateStringcreateHTML(ServletContextcontext,Map<String,Object>data,StringtemplatePath){
ConfigurationfreemarkerCfg=newConfiguration();
freemarkerCfg.setServletContextForTemplateLoading(context,"/");
freemarkerCfg.setEncoding(Locale.getDefault(),"UTF-8");
Templatetemplate=null;
try{
template=freemarkerCfg.getTemplate(templatePath,"UTF-8");
template.setEncoding("UTF-8");
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
if(null!=template){
StringWriterout=newStringWriter();
try{
template.process(data,out);
}catch(TemplateExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}
returnout.getBuffer().toString();
}
returnnull;
}