二。第一种方法
1.在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>
2.jsp页面中加入
<iframe src="/SunECM/public/view/test.doc" align="middle" style="margin-left: 100" width="90%" height="90%"></iframe>
********************以上两步即可。。。。。。。。。
二。第二种方法
在jsp页面添加
<%
File f = new File("C:/Users/joner/Desktop/test.doc "); //写自己文件路径
FileInputStream fin = new FileInputStream(f);
OutputStream output = response.getOutputStream();
byte[] buf = new byte[1024];
int r = 0;
response.setContentType("application/msword;charset=GB2312 ");
while ((r = fin.read(buf, 0, buf.length)) != -1) {
output.write(buf, 0, r); //response.getOutputStream()
}
fin.close();
output.close();
%>
在jsp页头引入
<%@page contentType="application/msword;charset=gbk"%>
这是在浏览器中已word形式打开
<%@page contentType="application/vnd.ms-excel;charset=gbk"%>
这是以excel。。。。。。