freemarker 生成word时 数据已经通过template注入完成了,然后输出流完成了,但是文件没有被生成
我的代码是这样写的publicword(){System.out.println("=======begin=======");configuration=newConf...
我的代码是这样写的
public word() { System.out.println("=======begin=======");
configuration = new Configuration();
configuration.setDefaultEncoding("UTF-8");}
public void createDoc(Map datamap, String path, String filename,
HttpServletResponse response) {
TemplateLoader templateLoader = null;
Template template = null;
try {
templateLoader = new ClassTemplateLoader(model.class);
configuration.setTemplateLoader(templateLoader);
template = configuration.getTemplate(path,"UTF-8");
template.setEncoding("UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
Writer out = null;
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
response.setHeader("content-disposition",
"attachment; filename=" + new String(filename.getBytes("GB2312"), "ISO-8859-1"));
out =new BufferedWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8"), 10240);
} catch (Exception e) { e.printStackTrace();
}
try {
template.process(datamap, out);
out.close();
} catch (TemplateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} 展开
public word() { System.out.println("=======begin=======");
configuration = new Configuration();
configuration.setDefaultEncoding("UTF-8");}
public void createDoc(Map datamap, String path, String filename,
HttpServletResponse response) {
TemplateLoader templateLoader = null;
Template template = null;
try {
templateLoader = new ClassTemplateLoader(model.class);
configuration.setTemplateLoader(templateLoader);
template = configuration.getTemplate(path,"UTF-8");
template.setEncoding("UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
Writer out = null;
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
response.setHeader("content-disposition",
"attachment; filename=" + new String(filename.getBytes("GB2312"), "ISO-8859-1"));
out =new BufferedWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8"), 10240);
} catch (Exception e) { e.printStackTrace();
}
try {
template.process(datamap, out);
out.close();
} catch (TemplateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} 展开
展开全部
应该是没有成功生成,内部代码里还包含了word无法识别的代码块,所以无法打开,你可以用记事本查看源代码,freenarker转换的word源代码都是xml格式
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |