我用的是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();
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();
这个是浏览器功能,和jsp无关。
是的,但是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你可以挑选出常用的几个。
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;
}