在jsp中怎样用一个链接能下载MYSQL中BLOB的数据 大侠写出代码

解决方案 »

  1.   

    你是说例如图片??
    像平常一样返回就行了啊
    我用servlet写过
    页面请求img( <img src='hello.do'></img>)hello.do是你部署好的servlet
    然后servlet把数据取出来返回给页面就行了
    好像返回之前还要改下返回类型,记不太清了
      

  2.   

    给你参考一下function downloadDoc(){
    var rid = document.getElementById('recordID').value;
    window.location.href="${ctx}/user/downloadDocFile.do?recordId="+rid;
       }
    <a href="#" onClick="downloadDoc()">
                 ${doclist.docDesc }
                 </a>
                 <input type="hidden" id="recordID" value="${doclist.recordId }">public ActionForward downloadDocFile(ActionMapping mapping,
    ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception { String recordId = request.getParameter("recordId");
    Integer docRecordId;
    try {
    docRecordId = new Integer(recordId);
    } catch (Exception e) {
    docRecordId = null;
    }
    if (docRecordId != null) { CamDoc cd = camDocControl.findByRecordID(new Integer(recordId)); byte[] doc = cd.getDocObject(); response.setContentType("application/octet-stream; charset=GBK");
    response.setContentLength(doc.length);
    response.setHeader("Content-disposition",
    "attachment; filename="
    + new String(cd.getFileName().getBytes("GBK"),
    "ISO-8859-1"));
    response.getOutputStream().write(doc); }
    return null;
    }