http://test.jssjys.com/Test.html
问题描述 : 如果电脑上没安装下载工具,直接点击此链接,压缩包就会被直接打开,上面的链接是真实的
大家可以点击看看, 怎样才能 弹出系统默认 下载框。
问题描述 : 如果电脑上没安装下载工具,直接点击此链接,压缩包就会被直接打开,上面的链接是真实的
大家可以点击看看, 怎样才能 弹出系统默认 下载框。
解决方案 »
- html标签与struts
- 谁能给我一个 MyBatis3.03 insert的例子 ?诡异了 晕
- ibm portal 读取exchange 2003邮件
- 如何将表单中填写的文章按照最初的格式显示在网页中
- 有偿寻找简单 SPRING / HIBERNATE 构架论坛
- Struts的Action的一些属性的具体意思?
- 一道面试题
- eclipse配置tomcat问题
- ▆▆▆◣电脑没死机,java数据库程序就是跑不起来,怪问题!!!急!!!
- SSH框架中dao层,service层,action层应该处理哪些业务,编写哪些方面的代码算是符合规范的
- 学java一定要学oracle吗?
- digester 读XML文件问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.webapp.app.util.SystemParam;
import com.webapp.mail.outboxannex.domain.OutboxAnnex;
import com.webapp.mail.outboxannex.iservice.IOutboxAnnexService;
import com.webapp.struct.module.action.EmpowermentAction;public class OutboxAnnexDownAction extends EmpowermentAction
{
private IOutboxAnnexService outboxAnnexService;
public IOutboxAnnexService getOutboxAnnexService() {
return outboxAnnexService;
} public void setOutboxAnnexService(IOutboxAnnexService outboxAnnexService) {
this.outboxAnnexService = outboxAnnexService;
} public String query(HttpServletRequest req, HttpServletResponse resp,
Map views) throws Exception {
String idStr = req.getParameter("id");
if (idStr == null || idStr.equals("")) {
return null;
}
Map paramMap = new HashMap();
paramMap.put("id", Integer.parseInt(idStr)); OutboxAnnex annex = outboxAnnexService.query(Integer.parseInt(idStr));
if (annex == null) {
return null;
}
download(req, resp, annex.getFilename(), annex.getLocalname());
return null;
} public void download(HttpServletRequest request,
HttpServletResponse response, String fileName, String localName) {
String usercode = (String) request.getSession()
.getAttribute("usercode"); File file = new File(SystemParam.rootPath + "\\mail\\" + usercode
+ "\\" + fileName); response.setContentType("application/x-download");
try {
response.addHeader("Content-Disposition", "attachment;filename="
+ URLEncoder.encode(localName, "UTF-8"));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
} // response.setHeader("Content-disposition", "attachment;filename="
// + localName);
// response.setContentType("application/x-tar");
// long length = file.length();
// response.setHeader("Content_Length", length + ""); OutputStream os = null;
FileInputStream fis = null; try {
os = response.getOutputStream();
fis = new FileInputStream(file); byte[] buff = new byte[4096];
int i = 0;
while ((i = fis.read(buff)) != -1) {
os.write(buff, 0, i);
} fis.close();
os.flush();
os.close();
response.setStatus(HttpServletResponse.SC_OK);
response.flushBuffer();
} catch (IOException e) {
e.printStackTrace();
}
file = null;
os = null;
fis = null;
}
}
package com.webapp.mail.outboxannex.action;import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.webapp.app.util.SystemParam;
import com.webapp.mail.outboxannex.domain.OutboxAnnex;
import com.webapp.mail.outboxannex.iservice.IOutboxAnnexService;
import com.webapp.struct.module.action.EmpowermentAction;public class OutboxAnnexDownAction extends EmpowermentAction
{
private IOutboxAnnexService outboxAnnexService;
public IOutboxAnnexService getOutboxAnnexService() {
return outboxAnnexService;
} public void setOutboxAnnexService(IOutboxAnnexService outboxAnnexService) {
this.outboxAnnexService = outboxAnnexService;
} public String query(HttpServletRequest req, HttpServletResponse resp,
Map views) throws Exception {
String idStr = req.getParameter("id");
if (idStr == null || idStr.equals("")) {
return null;
}
Map paramMap = new HashMap();
paramMap.put("id", Integer.parseInt(idStr)); OutboxAnnex annex = outboxAnnexService.query(Integer.parseInt(idStr));
if (annex == null) {
return null;
}
download(req, resp, annex.getFilename(), annex.getLocalname());
return null;
} public void download(HttpServletRequest request,
HttpServletResponse response, String fileName, String localName) {
String usercode = (String) request.getSession()
.getAttribute("usercode"); File file = new File(SystemParam.rootPath + "\\mail\\" + usercode
+ "\\" + fileName); response.setContentType("application/x-download");
try {
response.addHeader("Content-Disposition", "attachment;filename="
+ URLEncoder.encode(localName, "UTF-8"));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
} // response.setHeader("Content-disposition", "attachment;filename="
// + localName);
// response.setContentType("application/x-tar");
// long length = file.length();
// response.setHeader("Content_Length", length + ""); OutputStream os = null;
FileInputStream fis = null; try {
os = response.getOutputStream();
fis = new FileInputStream(file); byte[] buff = new byte[4096];
int i = 0;
while ((i = fis.read(buff)) != -1) {
os.write(buff, 0, i);
} fis.close();
os.flush();
os.close();
response.setStatus(HttpServletResponse.SC_OK);
response.flushBuffer();
} catch (IOException e) {
e.printStackTrace();
}
file = null;
os = null;
fis = null;
}
}