在web.xml中加入
<mime-mapping>
<extension>doc</extension>
<mime-type>application/msword</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xls</extension>
<mime-type>application/msexcel</mime-type>
</mime-mapping>
<%
File f = new File("G:/9602.doc"); //写自己文件路径
FileInputStream fin = new FileInputStream(f);
OutputStream output = response.getOutputStream();
byte[] buf = new byte[1024];
int r = 0;
response.setContentType("application/msword;charset=GB2312");