如题,在网上找了很多,都不是很好,请教各位给个实例,谢谢!

解决方案 »

  1.   

    以前见过在ie中显示pdf文档, 但是不知道这么实现的..
      

  2.   

    为了正确处理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 
      

  3.   

    回复4楼: 这么把word文档嵌在jsp中呢?
      

  4.   

    <object codebase="test.doc">
      </object>刚才查了以下用object标签可以显示word,excel,pdf等文档.
      

  5.   


    jsp中有 <object> 标签吗?
      

  6.   


    我去试下,看,可以不可以在ie里面打开word文档。
      

  7.   


    我不是在新页面里面打开word文件。
      

  8.   

    给个实例吧:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <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文档呢?
      

  9.   


    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();
          }
    基本是这个意思,但能不能运行,还要调一下
      

  10.   


    我试过了,这种,打开的时候,不是在ie页面显示的,比如pdf,就是用pdf工具打开显示,excel文件就是excel工具打开,word文件用word工具打开。我要的是不管是pdf文件还是excel文件或者word文档,都在ie界面中显示。
      

  11.   

    以前见过在ie中显示pdf文档, 但是不知道这么实现的..
      

  12.   

    以前见过在ie中显示pdf文档, 但是不知道这么实现的..
      

  13.   

    LZ,我要的是不管是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
      

  14.   


    我最近刚做过,是在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>
      

  15.   

    其实用BI工具生成的pdf,excel,html,word都可以直接在web页面中显示的
      

  16.   

    今天才来有看到这个.给你推荐个控件,NTKO office.
    如果私人使用下载试用版就可以了.我开发过2个系统都使用了这个控件`我感觉还不错`呵呵.
    有啥问题可以讨论下.   liyong#metatnet.com(# to @)
      

  17.   

    标注下 ,一会回来看 <object codebase="test.doc"> 这个是骗人的吧我测试了 根本什么都不显示