FreeMarker 乱码解决方案 生成静态html文件
2013-08-24 20:43
381 查看
读取模板的时候有一个编码:
Template template = this.tempConfiguration.getTemplate(templatePath,"UTF-8");
生成文件的时候使用编码:
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile), "UTF-8"));
附(freeMarker生成静态文件的代码):
View Code
Template template = this.tempConfiguration.getTemplate(templatePath,"UTF-8");
生成文件的时候使用编码:
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile), "UTF-8"));
附(freeMarker生成静态文件的代码):
public class MakeHtml { private Configuration tempConfiguration = new Configuration(); /** * 注意:所有位置相对于根目录 * @param path servletPath * @param data * @param templatePath 模板路径 * @param targetHtmlPath 保存路径 */ public void createHTML(String path, Map<String, Object> data, String templatePath, String targetHtmlPath) { try { //filepath:ftl存放路径(/template/file/static) System.out.println(path); this.tempConfiguration.setDirectoryForTemplateLoading(new File(path+"/freeMarker")); //templatePath:ftl文件名称(template.ftl) Template template = this.tempConfiguration.getTemplate(templatePath,"UTF-8"); // 静态页面要存放的路径 File htmlFile = new File(path + File.separator + targetHtmlPath); if(!htmlFile.getParentFile().exists()) { htmlFile.getParentFile().mkdirs(); } Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile), "UTF-8")); // 处理模版 map数据 ,输出流 template.process(data, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } } public void setTempConfiguration(Configuration tempConfiguration) { this.tempConfiguration = tempConfiguration; } }
View Code
相关文章推荐
- JSP中include静态文件HTML出乱码解决方案
- 使用FreeMarker生成Html静态文件(实例)
- JSP中include静态文件HTML出乱码解决方案
- 使用FreeMarker生成Html静态文件(实例)
- JAVA使用Freemarker生成静态文件中文乱码
- freemarker生成静态页面出现乱码解决方案
- JSP中include静态文件HTML出乱码解决方案
- springmvc+freemarker生成静态html文件
- JSP中include静态文件HTML出乱码解决方案
- 使用FreeMarker生成Html静态文件(实例)
- 利用Freemarker生成html静态页面,也可利用模版功能生成不同格式的文件
- Url地址重写,利用HttpHander手工编译页面并按需生成静态HTML文件
- jsp关于include html、jsp等文件出现乱码问题的解决方案
- 关于Freemarker生成静态html文件及中文乱码的问题
- 使用FreeMarker生成静态HTML
- jsp自动生成静态文件(html)
- 执行JSP后生成HTML静态文件【方法二】
- java 输入输出流将jsp文件生成html,解决乱码问题
- C#动态页面aspx生成静态html解决方案!
- jsp页面include静态文件html时导致的乱码问题.