主页 > 知识库 > 网络编程 > JSP/Java >

jsp打开word

来源:中国IT实验室 作者:佚名 发表于:2013-04-27 13:30  点击:
%@ page language=java contentType=application/msword;charset=GBK% !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN %@page import=java.io.File% %@page import=java.io.OutputStream% %@page import=java.io.InputStream% %@page import=
 <%@ page language="java" contentType="application/msword;charset=GBK"%>  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <%@page import="java.io.File"%>
  <%@page import="java.io.OutputStream"%>
  <%@page import="java.io.InputStream"%>
  <%@page import="java.io.FileInputStream"%>
  <html>
  <body>
  <%
  try{
  String fileName=request.getRealPath("/")+"/domain/erp组织机构树使用.doc";
  System.out.println("====="+fileName);
  File wordFile = new File(fileName);
  response.reset();
  response.setContentType( "application/msword ");
  response.setHeader( "Content-Disposition ", "inline;   filename= "+wordFile.getName());
  InputStream is =new FileInputStream(wordFile);
  OutputStream os = response.getOutputStream();
  int byteread;
  byte[] buffer=new byte[1024];
  while((byteread=is.read(buffer))!=-1){
  os.write(buffer,0,byteread);
  }
  os.flush();
  os.close();
  os.close();
  }catch(Exception e){
  e.printStackTrace();
  }
  %>
  </body>
  </html>

    有帮助
    (0)
    0%
    没帮助
    (0)
    0%