如题,在网上找了很多,都不是很好,请教各位给个实例,谢谢!
解决方案 »
- 编写bat文件关闭tomcat更新tomcat下面的war包再启动tomcat
- servlet中给mysql数据库插入的中文,在mysql控制台中能正常显示,但是从tomcat6中显示乱码
- 高薪寻求人才,以公司创始人身份享有公司股份(三天内有效)
- 一个至今无人能解决的问题。。。
- 300分求救!!不知道哪里出了错啊。。 救救我~~
- 在jsp 中传Hashtable的数据问题,(在线等)
- jsp 传值如何兼容各个浏览器
- 这句话的意思什么?我应该怎么理解每一行代码?我的cookie不是很理解
- 请问为什么会出现这样的编译错误?
- SSH框架配置文件部署问题applicationContext.xml
- Spring+Hibernate+JSON错误org.codehaus.jackson.map.JsonMappingException: No seriali
- java ee开发的系统前台是怎样取得数据的呢???
<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
</object>刚才查了以下用object标签可以显示word,excel,pdf等文档.
jsp中有 <object> 标签吗?
我去试下,看,可以不可以在ie里面打开word文档。
我不是在新页面里面打开word文件。
<head runat="server">
<title>无标题页</title>
</head><body>
<form id="form1" runat="server">
<div>
<a href="C:/Documents and Settings/Administrator/桌面/新建文件夹/1.doc" type="application/msword">打开word</a>
</div>
</form>
</body>
</html>我如何点击“打开word”超链接,就可以在当前ie里面显示word文档内容呢?就是我可以直接在ie里面阅读word文档呢?
String type = request.getParameter("type");
if(type.equals("excel") ||
type.equals("xls") ||
type.equals("txt") ||
"pdf".equals(type) ||
"xml".equals(type))
{
if(type.equals("excel"))
{
response.setContentType("application/vnd.ms-excel; charset=gb2312");
}
else if("pdf".equals(type))
{
response.setContentType("application/pdf; charset=gb2312");
}
else if("xml".equals(type))
{
response.setContentType("text/xml; charset=gb2312");
}
else
{
response.setContentType("application/x-msdownload; charset=gb2312");
}
response.setHeader("Content-disposition", "inline;filename=\"" + filename+ "\";");
InputStream is=null;
OutputStream os=null;
try{
is= new FileInputStream(fileurl);
os=response.getOutputStream();
int readLen=0;
while((readLen=is.read(bytes))!=-1){
os.write(bytes,0,readLen);
}
}catch(IOException ex){
logger.error(FormatUtil.getExceptionInfo(ex));
}finally{
if(is!=null) is.close();
if(os!=null) os.close();
}
基本是这个意思,但能不能运行,还要调一下
我试过了,这种,打开的时候,不是在ie页面显示的,比如pdf,就是用pdf工具打开显示,excel文件就是excel工具打开,word文件用word工具打开。我要的是不管是pdf文件还是excel文件或者word文档,都在ie界面中显示。
<c:if test="${(not empty attImgType) && attImgType=='jpg'}">
<div class="highslide-caption">
This caption can be styled using CSS.
</div>
<div id="closebutton" class="highslide-overlay closebutton" onclick="return hs.close(this)" title="Close"></div>
<a href="<c:url value="/imageShow"><c:param name="tableName" value="${tbName}"/><c:param name="id" value="${attImgId}"/></c:url>" class="highslide" onclick="return hs.expand(this)">
<img src='<c:url value="/imageShow"><c:param name="tableName" value="${tbName}"/><c:param name="id" value="${attImgId}"/></c:url>' title="Click to enlarge" height="400" width="500" /></a>
</c:if>
<c:if test="${(not empty attImgType) && attImgType=='tif'}">
<object width=100% height=360 id=obj1 classid="CLSID:106E49CF-797A-11D2-81A2-00E02C015623"
codebase="<c:url value="/alttiff.cab#version=1,8,1,1"/>">
<param name=src value="<c:url value="/imageShow"><c:param name="tableName" value="${tbName}"/><c:param name="id" value="${attImgId}"/></c:url>">
</object>
</c:if>
<c:if test="${(not empty attImgType) && (attImgType=='doc' || attImgType=='xls'||attImgType=='pdf')}">
<iframe src="<c:url value="/imageShow?tableName=${tbName}&id=${attImgId}"/>" width=100% height=450/>
</c:if>
楼主将就着看吧。加上一个iframe
我最近刚做过,是在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>
如果私人使用下载试用版就可以了.我开发过2个系统都使用了这个控件`我感觉还不错`呵呵.
有啥问题可以讨论下. liyong#metatnet.com(# to @)