用J下载word文件(不会直接用IE打开)_JSP技巧_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

用J下载word文件(不会直接用IE打开)

作者:黑客防线网安JSP教程基地 来源:黑客防线网安JSP教程基地 浏览次数:0

本篇关键词:打开直接不会文件
黑客防线网安网讯:  <%@page import="java.util.*"%>  <%@page import="java.io.*"%>  <%@page import="java.net.*"%>  <%      String filename = "";      if (request.getParameter("file") !...

  <%@page import="java.util.*"%>
  <%@page import="java.io.*"%>
  <%@page import="java.net.*"%>
  <%
      String filename = "";
      if (request.getParameter("file") != null) {
          filename =     request.getParameter("file");
      }
      response.setContentType("application/msword");
      response.setHeader("Content-disposition","attachment; filename="+filename);
      
      BufferedInputStream bis = null;
      BufferedOutputStream bos = null;
      try {
          bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + filename)));
          bos = new BufferedOutputStream(response.getOutputStream());
  
          byte[] buff = new byte[2048];
          int bytesRead;
  
          while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
              bos.write(buff,0,bytesRead);
          }
  
      } catch(final IOException e) {
          System.out.println ( "出现IOException." + e );
      } finally {
          if (bis != null)
              bis.close();
          if (bos != null)
              bos.close();
      }
      return;
  %>

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-16458-1.html
网站维护教程更新时间:2012-04-07 00:22:34  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer