首页 > Web开发 > 详细

servlet文件下载和jspsmartupload上传

时间:2015-10-09 12:05:31      阅读:203      评论:0      收藏:0      [点我收藏+]
SmartUpload smart = new SmartUpload();
            org.lxh.smart.Request re = smart.getRequest();
            smart.initialize(pageContext);
            smart.upload();
            String ext = smart.getFiles().getFile(0).getFileExt();
            Time time = new Time(request.getRemoteAddr());
            //Time time = new Time("127.0.0.1");
            String fileName = time.getIPTimeRand() + "." + "docx";
            String path = getServletContext().getRealPath("/")+"teacher" 
                    + java.io.File.separator + fileName;
            smart.getFiles().getFile(0).saveAs(path);

 

String path = request.getParameter("path");
        String name = request.getParameter("name");
        File f = new File(path);
         if(f.exists()){  
                       FileInputStream  fis = new FileInputStream(f);  
                       byte[] b = new byte[fis.available()];  
                       fis.read(b);  
                       response.setCharacterEncoding("gbk");  
                        response.setHeader("Content-Disposition","attachment; filename="+name+".docx");  
                        //获取响应报文输出流对象   
                         ServletOutputStream  out =response.getOutputStream();  
                         //输出   
                         out.write(b);  
                         out.flush();  
                         out.close();  
                                  
                             
                         }

 

servlet文件下载和jspsmartupload上传

原文:http://www.cnblogs.com/84126858jmz/p/4863269.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!