如何在jsp页面显示一个已有的word文档如何在jsp页面显示一个已有的word文档
浏览次数:次悬赏分:解决时间:提问者:90510 | 2009-5-30 14:24 | lhjq780
我用的是ssh,要在jsp页面上显示一个word文档,具体怎么做,望高人指点
一下
问题补充:
方便的,麻烦上的代码,感谢不尽
我的word文档的文件名是在数据库查出来的,从后来传过来的,想在前台直接
显示的
最佳答案
");
out.close();
return;
}
response.setContentType("application/ms...
如何在jsp页面显示一个已有的word文档
浏览次数:次悬赏分:解决时间:提问者:90510 | 2009-5-30 14:24 | lhjq780
我用的是ssh,要在jsp页面上显示一个word文档,具体怎么做,望高人指点
一下
问题补充:
方便的,麻烦上的代码,感谢不尽
我的word文档的文件名是在数据库查出来的,从后来传过来的,想在前台直接
显示的
最佳答案
<%@page contentType="application/msword;charset=utf8"%> <%@page import="java.io.*"%>
<%
String filename = "";
if (request.getParameter("docfilename") != null) {
filename = request.getParameter("docfilename");
}
File f = new File(filename);
if(!f.exists() || f.isDirectory()){
out.println("");
out.close();
return;
}
response.setContentType("application/msword");
response.setHeader("Content-disposition","attachment; filename=mc.doc");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(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(FileNotFoundException fe){
System.out.println("文件没找到");
} catch(final IOException e) {
System.out.println ( "出现IOException." + e );
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
out.clear();
out = pageContext.pushBody();
}
return;
%>
本文档为【如何在jsp页面显示一个已有的word文档】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。