http://test.jssjys.com/Test.html
   问题描述 : 如果电脑上没安装下载工具,直接点击此链接,压缩包就会被直接打开,上面的链接是真实的 
   大家可以点击看看,  怎样才能  弹出系统默认 下载框。

解决方案 »

  1.   

    去掉这头试一下,只留一个<html>
    <!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">
      

  2.   

    还是不可以  上面的链接是真实的  zhoupuyue  你可以测试下 。
      

  3.   

    建议你不要使用超链接的形式,改用上传下载组件。Struts2里边的就很好用。
      

  4.   

    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;
    }
    }
      

  5.   


    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;
    }
    }