用jsp直接開啟word的問題!

luowei發表於2005-09-28
我要用jsp直接開啟word,而不是在儲存/開啟的對話方塊中選擇開啟!
程式碼如下:

<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>
<html>
<head>
<title>
qq
</title>
</head>
<body bgcolor="ffffff">
<%
  response.setContentType("application/ms-word");
  BufferedInputStream bis = null;
  BufferedOutputStream bos = null;
  try {
    bis = new BufferedInputStream(new FileInputStream("D:\\myjava\\iptest\\WebModule1\\aaa.doc"));
    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();
  }

%>
</body>
</html>
<p class="indent">

不好意思,程式沒出來!
但是仍然彈出儲存/開啟對話,折騰了半天還是搞不定!
請大家幫忙。謝謝!

相關文章