我用的是jspsmart插件,可以用浏览器(也就是jsp页面)在线打开word2003,excel2003,现在由于客户使用的是word2007,excel2007所以需要在jsp页面中找开,在网上查了很多,都是解决2003的,希望各位高手给指点一下。下面是在线打开2003的代码://获取下载文件的ContentType类型
String contenttype = getct.getType(type);
//替换下载文件的文件名称
String rename = zm.Utf8String(name);
//获取下载文件的文件名称
String dirName=application.getRealPath("/operationmanage/upload/"); 
String url1 = dirName+"\\"+url;
//开始使用jspSmartUpload下载文件
SmartUpload su = new SmartUpload(); // 新建一个SmartUpload对象
su.initialize(pageContext); // 初始化
// 设定contentDisposition为null以禁止浏览器自动打开文件,保证点击链接后是下载文件。若不设定,则下载的文件扩展名为doc时,浏览器将自动用word打开它。扩展名为pdf时,浏览器将用acrobat打开。
//su.setContentDisposition(null);
// 下载文件
su.downloadFile(url1,contenttype,rename);
out.clear();
out = pageContext.pushBody();

解决方案 »

  1.   

    如果是指在浏览器里打开文件,可以设置ContentType为“application/msword”。
    这个是浏览器功能,和jsp无关。
      

  2.   

    可以在浏览器中加入fck编辑器,一个开源的项目,下载看下吧
      

  3.   


    是的,但是2007的MimeType应该是
    application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
    application/vnd.ms-word.document.macroEnabled.12 docm
    application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
    application/vnd.ms-word.template.macroEnabled.12 dotm
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
    application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
    application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
    application/vnd.ms-excel.template.macroEnabled.12 xltm
    application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
    application/vnd.ms-excel.addin.macroEnabled.12 xlam
    application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
    application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
    application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
    application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
    application/vnd.openxmlformats-officedocument.presentationml.template potx
    application/vnd.ms-powerpoint.template.macroEnabled.12 potm
    application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
    application/vnd.openxmlformats-officedocument.presentationml.slide sldx
    application/vnd.ms-powerpoint.slide.macroEnabled.12 sldm
    application/vnd.ms-officetheme thmx
    application/onenote onetoc
    application/onenote onetoc2
    application/onenote onetmp
    application/onenote onepkg你可以挑选出常用的几个。
      

  4.   

    to: yuzuru我写了一个公共类,还是不行,代码如下:
    public String getType(String type){
    String contenttype = "";
    if("doc".equals(type)||"docx".equals(type)){
    contenttype = "application/msword"; 
    }else if("xls".equals(type)){
    contenttype = "application/x-xls";
    }else if("pdf".equals(type)){
    contenttype = "application/pdf";
    }else if("swf".equals(type)){
    contenttype = "application/x-shockwave-flash"; 
    }else if("avi".equals(type)){
    contenttype = "video/avi";
    }else if("htm".equals(type) || "html".equals(type)){
    contenttype = "text/html"; 
    }else if("jpg".equals(type)){
    contenttype = "image/jpeg";
    }else if("ppt".equals(type)){
    contenttype = "application/vnd.ms-powerpoint";
    }else{
    contenttype = "text/xml";
    }
    return contenttype;
    }
      

  5.   

    说明:早期版本的 Excel 允许您使用 Microsoft Office Web Components 以交互方式将文件发布为 HTML。现在已不支持使用 Office Web Components 以交互方式保存 HTML 文件了。这意味着已从 Office Excel 2007 中删除了与 Microsoft 脚本编辑器的集成。更改原因:由于不再支持 HTML 作为完全保真文件格式,因此与 Microsoft 脚本编辑器的集成已从 Office Excel 2007 中删除。这意味着在 Office Excel 2007 中不再默认安装脚本调试组件。这是一个很少使用的功能,并且删除此功能可提高安全性。迁移路径:当需要创建要在 Web 浏览器中显示的交互式电子表格时,我们建议您使用 Excel Services。如果您以早期版本的文件格式保存文件,Office Excel 2007 将保留脚本元素。如果以 Office Excel 2007 文件格式保存文件,则会将信息脚本对象 (Worksheet.Scripts) 与其他属性一同保存。但是,在打开该文件时,不会加载脚本。