求救 弹出下载对话框 没明白你的意思,重新组织一下你的语言,下载是指下载什么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用servlet写的一个下载程序代码,当servlet走完转到jsp页面的时候会弹出一个下载确认的对话框。当我点击对话框上的打开按钮时,会再次弹出对话框,再点击一次打开按钮才会真的打开文件。我的代码如下: try { String fileName=null; String fileUrl=null; fileUrl=struct.getRealFileName();// fileName=struct.getGA1_FILE_NM(); int indexs = fileUrl.lastIndexOf("/"); if (indexs != -1) { fileName = fileUrl.substring(indexs + 1); }// fileUrl = CoreTools.getContainer().getString ("nis.screen.pattern.fileupload.dir");// if (fileUrl == null || fileUrl.length() == 0) {// fileUrl = "C:\\OrteusProj\\upload\\";// } response.reset(); response.setContentType("application/x-msdownload"); response.addHeader("Content-Disposition","attachment; filename=\"" + fileName + "\""); File file = new File(fileUrl); if(file.exists()){ FileInputStream in = new FileInputStream(file); OutputStream out = response.getOutputStream(); byte[] b = new byte[100]; int len; while ((len = in.read(b)) > 0) { out.write(b, 0, len); } if(in!=null){ in.close(); } if(out!=null){ out.close(); } } } catch(Exception e) { e.printStackTrace(); }是我的contentType没具体指定吗?请指教。谢谢 兼容问题 cursor 如何在IE中鼠标兼容图片样式 struts编译问题 <html:select>从数据库读取数据 java怎么实现一个类在session有效期间持续作用? 关于翻页,jsp页面中想把记录一次性全部加载到内存中,然后从内存中取! 简单的格行颜色问题! jsp连接mysql,是否要jdbc驱动,如何安装呢? session怎么使用 如何使用ant,急! 如何保持EJB对象 请教两个关于jsp中的中文显示的问题,非常急 毕设题目
当我点击对话框上的打开按钮时,会再次弹出对话框,再点击一次打开按钮才会真的打开文件。
我的代码如下:
try {
String fileName=null;
String fileUrl=null;
fileUrl=struct.getRealFileName();
// fileName=struct.getGA1_FILE_NM();
int indexs = fileUrl.lastIndexOf("/");
if (indexs != -1) {
fileName = fileUrl.substring(indexs + 1);
}
// fileUrl = CoreTools.getContainer().getString
("nis.screen.pattern.fileupload.dir");
// if (fileUrl == null || fileUrl.length() == 0) {
// fileUrl = "C:\\OrteusProj\\upload\\";
// }
response.reset();
response.setContentType("application/x-msdownload");
response.addHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
File file = new File(fileUrl);
if(file.exists()){
FileInputStream in = new FileInputStream(file);
OutputStream out = response.getOutputStream();
byte[] b = new byte[100];
int len;
while ((len = in.read(b)) > 0) {
out.write(b, 0, len);
}
if(in!=null){
in.close();
}
if(out!=null){
out.close();
}
}
} catch(Exception e) {
e.printStackTrace();
}
是我的contentType没具体指定吗?请指教。谢谢