求一个实例,jsp页面中,点击文件的超链接,就在ie中显示word、excel、pdf、txt、html文档的内容!

oraclelogan 2009-07-24 09:38:10
如题,在网上找了很多,都不是很好,请教各位给个实例,谢谢!
...全文
1486 27 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zhengjie322 2011-11-18
  • 打赏
  • 举报
回复
[Quote=引用 21 楼 ohmydog1 的回复:]
我最近刚做过,是在ie窗口里的啊。


web.xml

XML code


.....
<mime-mapping>
<extension>doc</extension>
<mime-type>application/msword</mime-type>
</mime-mapping>

<mime-ma……
[/Quote]

干嘛我在IE中是乱码的?
copiy 2010-11-12
  • 打赏
  • 举报
回复
标注下 ,一会回来看

<object codebase="test.doc">

这个是骗人的吧

我测试了 根本什么都不显示
tacoley 2009-08-30
  • 打赏
  • 举报
回复
今天才来有看到这个.给你推荐个控件,NTKO office.
如果私人使用下载试用版就可以了.

我开发过2个系统都使用了这个控件`我感觉还不错`呵呵.
有啥问题可以讨论下. liyong#metatnet.com(# to @)
oraclelogan 2009-07-31
  • 打赏
  • 举报
回复
谢谢大家,不过还是没有搞定啊!
xiaochengfu1 2009-07-24
  • 打赏
  • 举报
回复
学习,我也想要这个
oraclelogan 2009-07-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tacoley 的回复:]
为了正确处理word 等格式,你需要在HTML文件中设置好该文件类型,比如:
<meta http-equiv="Content-Type" content="application/msword">
  还有其它经常设置的文件类型:
application/msword Microsoft Word Document
application/pdf PDF Document
application/wordperfect6.0 WordPerfect 6.0 Document
application/zip ZIP archive
audio/x-wav WAV audio format
audio/midi MIDI audio format
audio/x-pn-realaudio RealAudio
image/gif GIF image format
image/jpeg JPEG image format
image/png PNG image format
text/html HTML document
text/plain Plain text
video/mpeg MPEG video format
video/quicktime QuickTime video format
video/x-msvideo AVI video format
[/Quote]

我不是在新页面里面打开word文件。
oraclelogan 2009-07-24
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zhaohuizixin 的回复:]
引用 8 楼 oraclelogan 的回复:

jsp中有 <object> 标签吗?


当然有啊, 我试过了.

[/Quote]

jsp里面好像不好使的。
oraclelogan 2009-07-24
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zhaohuizixin 的回复:]
引用 8 楼 oraclelogan 的回复:

jsp中有 <object> 标签吗?


当然有啊, 我试过了.

[/Quote]

我去试下,看,可以不可以在ie里面打开word文档。
ZhaoHuiZiXin 2009-07-24
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 oraclelogan 的回复:]

jsp中有 <object> 标签吗?
[/Quote]

当然有啊, 我试过了.
oraclelogan 2009-07-24
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zhaohuizixin 的回复:]
<object codebase="test.doc">
  </object>

刚才查了以下用object标签可以显示word,excel,pdf等文档.
[/Quote]

jsp中有 <object> 标签吗?
ZhaoHuiZiXin 2009-07-24
  • 打赏
  • 举报
回复
<object codebase="test.doc">
</object>

刚才查了以下用object标签可以显示word,excel,pdf等文档.
jinchun1234 2009-07-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tacoley 的回复:]
为了正确处理word 等格式,你需要在HTML文件中设置好该文件类型,比如:
<meta http-equiv="Content-Type" content="application/msword">
  还有其它经常设置的文件类型:
application/msword Microsoft Word Document
application/pdf PDF Document
application/wordperfect6.0 WordPerfect 6.0 Document
application/zip ZIP archive
audio/x-wav WAV audio format
audio/midi MIDI audio format
audio/x-pn-realaudio RealAudio
image/gif GIF image format
image/jpeg JPEG image format
image/png PNG image format
text/html HTML document
text/plain Plain text
video/mpeg MPEG video format
video/quicktime QuickTime video format
video/x-msvideo AVI video format
[/Quote]

设置这个大家都知道,关键是具体怎么代码实现在浏览器里面显示
ZhaoHuiZiXin 2009-07-24
  • 打赏
  • 举报
回复
回复4楼: 这么把word文档嵌在jsp中呢?
tacoley 2009-07-24
  • 打赏
  • 举报
回复
为了正确处理word 等格式,你需要在HTML文件中设置好该文件类型,比如:
<meta http-equiv="Content-Type" content="application/msword">
  还有其它经常设置的文件类型:
application/msword Microsoft Word Document
application/pdf PDF Document
application/wordperfect6.0 WordPerfect 6.0 Document
application/zip ZIP archive
audio/x-wav WAV audio format
audio/midi MIDI audio format
audio/x-pn-realaudio RealAudio
image/gif GIF image format
image/jpeg JPEG image format
image/png PNG image format
text/html HTML document
text/plain Plain text
video/mpeg MPEG video format
video/quicktime QuickTime video format
video/x-msvideo AVI video format
oraclelogan 2009-07-24
  • 打赏
  • 举报
回复
等待,还有知道的没啊,给个样例啊!谢谢了!
ZhaoHuiZiXin 2009-07-24
  • 打赏
  • 举报
回复
以前见过在ie中显示pdf文档, 但是不知道这么实现的..
jinchun1234 2009-07-24
  • 打赏
  • 举报
回复
我也想要,呵呵!
努力 2009-07-24
  • 打赏
  • 举报
回复
其实用BI工具生成的pdf,excel,html,word都可以直接在web页面中显示的
fancyoo1 2009-07-24
  • 打赏
  • 举报
回复
咦。。。。不错。。
ohmydog1 2009-07-24
  • 打赏
  • 举报
回复

我最近刚做过,是在ie窗口里的啊。


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>

<mime-mapping>
<extension>pdf</extension>
<mime-type>application/pdf</mime-type>
</mime-mapping>
</web-app>


viewFile.jsp

<%@ page language="java" import="java.util.*,java.io.*" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>viewDoc</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<%
String file="test.doc";
if(request.getParameter("file")!=null){
file=request.getParameter("file");
}
java.io.File f=new java.io.File(this.getServletContext().getRealPath("/")+"//file//"+file);
if(f.exists()&&f.isFile()){
FileInputStream fin=new FileInputStream(f);
OutputStream output=response.getOutputStream();
byte[] buf=new byte[1024];
int r=0;
if(file.toLowerCase().endsWith(".doc")){
response.setContentType("application/msword;charset=utf-8");
}else if(file.toLowerCase().endsWith(".xls")){
response.setContentType("application/vnd.ms-excel;charset=utf-8");
}else{
out.println("file type error!");
fin.close();
output.close();
out.clear();
out = pageContext.pushBody();
return;
}

while((r=fin.read(buf,0,buf.length))!=-1)
{
output.write(buf,0,r);//response.getOutputStream()
}
fin.close();
output.close();
out.clear();
out = pageContext.pushBody();
}
else{
out.println("file error!");
}
%>

</body>
</html>

加载更多回复(7)

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧