我用的是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();
解决方案 »
- 求救!使用JDNI时,报 Cannot create JDBC driver of class '' for connect URL 'null'
- 框架的XML配置和Annotation配置可以混着用吗
- ireport问题
- eclipse打开jsp突然变成黑白了
- form submit的问题,解决了立马给分,3Q
- 怎样格式化输出显示?
- jsp在Tomcat中的应用!!
- 关于页面中用到文件上传组件时,form中包含ENCTYPE="multipart/form-data"的取值问题?
- 一个Vector应用的问题
- JS发布到服务器上,有的用户访问到更新的JS页面,还是显示老版本的JS,更新上去的没有起作用!!!求教!!!
- jdbc事务无法由spring控制
- 用httpClient3.x发送http请求服务器得不到数据
这个是浏览器功能,和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;
}