我的逻辑是这样的
public void A(){
//这里从数据库中把需要的数据取出来
//调用方法b 把数据传过去
}
public void B(){
String filepath = "";
String export_path = "";
String filename = "";
String tmppath = PathKit.getWebRootPath() + "\\WEB-INF\\views\\" + "template.doc";
InputStream is = null;
try {
is = new FileInputStream(tmppath);
HWPFDocument doc = new HWPFDocument(is);
Range range = doc.getRange();
String created = map.get("created").toString();
String paper_name = map.get("paper_name").toString();
String creator = map.get("creator").toString();
String content = map.get("content").toString();
range.replaceText("${created}", created);
range.replaceText("${paper_name}", paper_name);
range.replaceText("${creator}", creator);
range.replaceText("${content}", content);
String filedir = PathKit.getWebRootPath() + "\\exportword\\" + paper_name + "_" + created;
File file = new File(filedir);
if (!file.exists()) {
System.out.println("目录不存在!生成目录!");
file.mkdirs();
} else {
System.out.println("目录已存在!");
}
filepath = filedir + "\\" + creator + "_" + created + ".doc";
export_path = PathKit.getWebRootPath() + "\\exportword\\" + paper_name + "_" + created + "\\" + creator + "_" + created + ".doc";
OutputStream os = new FileOutputStream(filepath);
doc.write(os);
this.closeStream(os);
this.closeStream(is);
filename = creator + "_" + created + ".doc";
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//使用poi 将数据写入并生成到一个word中 文件确实也已经生成了
//调用方法c 将这个文件的绝对路径传过去
this.C(export_path);
}
public void C(String filepath){
File file = new File(filename);
System.out.println("file=" + file.isFile());
renderFile(file);
}
然后。。。就没有然后了。。。
也没有任何报错
当然也没有下载的反应
但是如果我直接访问C方法 并直接指定一个路径 是可以下载的 但是我的文件都是动态生成的 所以直接访问这个方法不大现实 我也不想把所有的方法和代码都挤在一个方法里。。。
求大神指点迷津
之前有看到波哥在http://www.oschina.net/question/863262_77708 里回复的 但是还是没实现
@JFinal 波哥求指导
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
你的renderFile(fileName)这一行代码在哪里?在c方法中把文件路径传进来用的是renderFile(Filefile)的你可以先试试直接在B中renderFile(filepath);估计是因为你前台请求的是B,但是在B中又调用C来renderFile(),这种方法可能行不通,具体为什么就要问JFinal了; 你如果想代码分离,你可以把B写到一个工具类里,生成word后returnfilePath;然后前台直接请求C,在C中调用B,B中需要什么参数,由C传过去;
谢谢回复!我调用的过程是前端请求A然后A中调用BB中调用C然后Crenderfilec中的文件路径是由b传过来的由于是生成多个独立文件所以需要输出很多次我先试试你的建议看看行不行再次感谢!
问题已解决谢谢@_时光的提示
我把所有的文件都打包成一个压缩包只在C方法里调用AB方法然后返回压缩包的路径
然后直接renderFile(压缩包)了