保存对话框怎么调用? 相对于<input type="file"/>我想做个备份. 在网页上选择保存路径,点击“备份”按钮可以把数据库备份到指定位置就是不知道怎么能上传那个路径?那个选择保存路径的对话框怎么弄出来? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String filePath = "路径文件名"; resp.reset(); if (filePath.endsWith(".doc") || filePath.endsWith(".rtf")) { resp.setContentType("application/msword"); resp.setHeader("Content-disposition", "inline; filename=" + URLEncoder.encode(fileName, "UTF-8")); } else if (filePath.endsWith(".pdf")) { resp.setContentType("application/pdf"); resp.setHeader("Content-disposition", "inline; filename=" + URLEncoder.encode(fileName, "UTF-8")); } else if (filePath.endsWith(".xls")) { resp.setContentType("application/vnd.ms-excel"); resp.setHeader("Content-disposition", "inline; filename=" + URLEncoder.encode(fileName, "UTF-8")); } else { resp.setContentType("application/x-msdownload"); resp.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8")); } File file = new File(filePath);// 如果是相对路径 if(!file.exists()) file = new File(req.getSession().getServletContext().getRealPath("/"+ filePath)); FileInputStream in = org.apache.commons.io.FileUtils .openInputStream(file); ServletOutputStream sout = resp.getOutputStream(); int filesize = org.apache.commons.io.IOUtils.copy(in, sout); sout.close(); java web项目下的一些文件 注册模块出错 新手求助 在线等 求助,关于JSP页面的问题! jsp被翻译成.java后,其中的releasePageContext都干了些什么? 404问题 请问 哪里可以下载到sybase驱动jconn2.jar 哪位大大来帮忙看下我的代码哪里有错误 谢谢啦 啊啊 请问RequestDispatcher怎么用?我这样用有什么错? 字符比较的问题 微信群发接口中的群发视频接口遇到的问题, 在线等!! jsp如何在javabean中实现数据库连接? 如是使用JAVA向IE工具栏中添加一个可以操作浏览器当前URL的按钮
resp.reset();
if (filePath.endsWith(".doc") || filePath.endsWith(".rtf")) {
resp.setContentType("application/msword");
resp.setHeader("Content-disposition", "inline; filename="
+ URLEncoder.encode(fileName, "UTF-8"));
} else if (filePath.endsWith(".pdf")) {
resp.setContentType("application/pdf");
resp.setHeader("Content-disposition", "inline; filename="
+ URLEncoder.encode(fileName, "UTF-8"));
} else if (filePath.endsWith(".xls")) {
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-disposition", "inline; filename="
+ URLEncoder.encode(fileName, "UTF-8"));
} else {
resp.setContentType("application/x-msdownload");
resp.setHeader("Content-disposition",
"attachment; filename="
+ URLEncoder.encode(fileName, "UTF-8"));
}
File file = new File(filePath);
// 如果是相对路径
if(!file.exists())
file = new File(req.getSession().getServletContext().getRealPath("/"+ filePath));
FileInputStream in = org.apache.commons.io.FileUtils
.openInputStream(file);
ServletOutputStream sout = resp.getOutputStream();
int filesize = org.apache.commons.io.IOUtils.copy(in, sout);
sout.close();