package com.guanghua.util;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Locale;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class CreateHtml {
/**
* @author xingyunpi
* @param ftl 模板文件
* @param htmlName 生成html文件
* @param map
* @param relaPath
* @throws IOException
* @throws TemplateException
*/
public void init (String ftl,String htmlName,Map map,String relaPath) throws IOException,TemplateException{
Configuration cfg=new Configuration();
cfg.setServletContextForTemplateLoading(ServletActionContext.getServletContext(), "/");
cfg.setEncoding(Locale.getDefault(), "UTF-8");
Template template=cfg.getTemplate(ftl);
template.setEncoding("UTF-8");
String path=ServletActionContext.getServletContext().getRealPath("/");
File fileName=new File(path+htmlName);
Writer out=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName),"UTF-8"));
template.process(map, out);
out.flush();
out.close();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
生成静态页面 freemarker模板
共27个文件
prefs:4个
xml:3个
class:3个
4星 · 超过85%的资源 需积分: 15 147 下载量 133 浏览量
2012-03-03
17:04:48
上传
评论
收藏 1.52MB RAR 举报
温馨提示
用freemarker做模板,结合struts2生成静态页面功能,不要分,嘻嘻
资源推荐
资源详情
资源评论
收起资源包目录
CreateHtml.rar (27个子文件)
CreateHtml
.mystrutsdata 240B
.myhibernatedata 545B
.myumldata 66B
.settings
com.genuitec.eclipse.j2eedt.core.prefs 1KB
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.core.resources.prefs 159B
com.genuitec.jboss.ide.eclipse.xdoclet.run.prefs 120B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.ws.service.policy.prefs 118B
.jsdtscope 500B
src
com
guanghua
action
HtmlTest.java 1KB
Person.java 295B
util
CreateHtml.java 1KB
struts.xml 496B
.project 2KB
WebRoot
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 677B
classes
com
guanghua
action
Person.class 729B
HtmlTest.class 2KB
util
CreateHtml.class 2KB
struts.xml 496B
lib
freemarker2.3.18.jar 903KB
mysql-connector-java-5.1.15-bin.jar 768KB
person.ftl 825B
index.jsp 1KB
.mymetadata 304B
.classpath 636B
.myeclipse
共 27 条
- 1
xingyunpi
- 粉丝: 45
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页