public String nongweiDownLoad(){
String fileName = "网络新闻观察"+DateUtil.getChtsDate(new Date())+".doc";
//获取dataMap start
Map<String, Object> dataMap = this.autoRepDocService.getNWRepData(treeId, reportTime);
Configuration configuration = new Configuration();
configuration.setDefaultEncoding("utf-8");
configuration.setClassForTemplateLoading(this.getClass(), "/com/luoan/yuqing/template/");
Template t=null;
try {
//test.ftl为要装载的模板
t = configuration.getTemplate("nongwei.ftl");
} catch (IOException e) {
logger.error(e.getMessage());
}
ActionContext ctx = ActionContext.getContext();
HttpServletResponse response = (HttpServletResponse) ctx
.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse");
response.setContentType("application/msword");
try {
HttpServletRequest request = ServletActionContext.getRequest();
fileName = processFileName(request, fileName);
response.addHeader("Content-Disposition", "attachment; filename="+fileName);
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
t.process(dataMap, out);
out.close();
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
} catch (TemplateException e) {
logger.error(e.getMessage());
}
return null;
}
String fileName = "网络新闻观察"+DateUtil.getChtsDate(new Date())+".doc";
//获取dataMap start
Map<String, Object> dataMap = this.autoRepDocService.getNWRepData(treeId, reportTime);
Configuration configuration = new Configuration();
configuration.setDefaultEncoding("utf-8");
configuration.setClassForTemplateLoading(this.getClass(), "/com/luoan/yuqing/template/");
Template t=null;
try {
//test.ftl为要装载的模板
t = configuration.getTemplate("nongwei.ftl");
} catch (IOException e) {
logger.error(e.getMessage());
}
ActionContext ctx = ActionContext.getContext();
HttpServletResponse response = (HttpServletResponse) ctx
.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse");
response.setContentType("application/msword");
try {
HttpServletRequest request = ServletActionContext.getRequest();
fileName = processFileName(request, fileName);
response.addHeader("Content-Disposition", "attachment; filename="+fileName);
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
t.process(dataMap, out);
out.close();
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
} catch (TemplateException e) {
logger.error(e.getMessage());
}
return null;
}