java Web 项目 怎样将获取客户端的路径, 将文件流输出到客户端生成文件0
PPMMX2014.05.05浏览221次分享举报
我思路是通过装载模版,将模版转换成流,然后将需要插入到模版中的数据与模版流一起向指定的路径输出生成文件,现在这个指定的路径能数据,但是项目部署到服务器上,文件生成在服务器上指定的目录里,我想生成在客户端的的指定目录(或者客户端浏览器点击按钮弹出选择保存路径的界面,类似于另存为的那种,不知道可不可以实现)
以下是源码, 还请各位多多指教,在此现行谢过~~
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 blocke.printStackTrace();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}try {t.process(dataMap, out);} catch (TemplateException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}try {out.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}