protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        OutputStream stream = null;
        BufferedInputStream buf = null;
        
        try {
            stream = response.getOutputStream();
            
            response.setContentType("application/msword");
            response.setHeader("Content-Disposition", 
                    "attachment;filename=" + new String("文档测试.doc".getBytes(), "iso8859-1"));
            
            String smbFile = "smb://用户名:密码@192.168.0.149/work/his/";
            String fileName = "测试.doc";
            SmbFile remoteFile = new SmbFile(smbFile+fileName);
                    
            buf = new BufferedInputStream(new  SmbFileInputStream(remoteFile));
            
            
            byte buff[] = new byte[2048];
            int readBytes = 0;
            while (-1 != (readBytes = buf.read(buff, 0, buff.length))) {
                stream.write(buff, 0, readBytes);
            }
            
        } catch (IOException ioe) {
            throw new ServletException(ioe.getMessage());
        } finally {
            if (stream != null) {
                stream.close();
            }
            if (buf != null) {
                buf.close();
            }
        }
    }

 

相关文章:

  • 2021-10-01
  • 2021-08-31
  • 2021-07-29
  • 2021-12-04
  • 2022-12-23
  • 2021-07-28
  • 2021-04-23
  • 2022-12-23
猜你喜欢
  • 2021-07-21
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
  • 2021-05-16
  • 2021-09-23
  • 2022-12-23
相关资源
相似解决方案