我思路是通过装载模版,将模版转换成流,然后将需要插入到模版中的数据与模版流一起向指定的路径输出生成文件,现在这个指定的路径能数据,但是项目部署到服务器上,文件生成在服务器上指定...
我思路是通过装载模版,将模版转换成流,
然后将需要插入到模版中的数据与模版流一起向指定的路径输出生成文件,
现在这个指定的路径能数据,但是项目部署到服务器上,
文件生成在服务器上指定的目录里,我想生成在客户端的的指定目录(或者客户端浏览器点击按钮弹出选择保存路径的界面,类似于另存为的那种,不知道可不可以实现)
以下是源码, 还请各位多多指教,在此现行谢过~~
Map map = null;
Map dataMap = new HashMap();
Configuration configuration = new Configuration();
configuration.setDefaultEncoding("utf-8");
map = WordDemoFactory.getRemoteInstance().rowSet("11010819621008373x00");
dataMap.putAll(map);
map = WordDemoFactory.getRemoteInstance().getStudy("11010819621008373x00");
dataMap.putAll(map);
//指定模版路径
configuration.setClassForTemplateLoading(this.getClass(), "/com/kingdee/eas/custom/word");
Template t = null;
try {
//装载模版
t = configuration.getTemplate("wordDemo.xml");
} catch (IOException ex) {
ex.printStackTrace();
}
String path = "D:\\temp";//导出文件存放路径
String fileName = "outFile.rtf";//文件名
File outFile = new File(path);//如果路径不存在,则创建
if(!outFile.exists()){
outFile.mkdir();
}
File file = new File(path+"\\"+fileName);//如果该路径存在该文件名的文件,则删除
if(file.exists()){
file.delete();
}
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path+"\\"+fileName), "utf-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
t.process(dataMap, out);
} catch (TemplateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
简单来说 就是我想做个导出功能
但是由于路径的原因只能导到服务器上 怎么才能导出到客户端上
展开