在jsp中怎样用一个链接能下载MYSQL中BLOB的数据 大侠写出代码
解决方案 »
- GoogleGson转换复杂java对象,请求帮忙!急急急!!!!!!!!!!!
- java 的拖放效果
- 咱想换个工作,做java开发和设计的,有需求的公司请联系我!
- 下拉框onchange事件问题?在线等待
- tomcat启动它的java程序,在catalina.bat是哪句批处理?
- websphere下配置数据源测试连接时报错,在线等,解决结帖`~
- Hibernate一对多关联的问题!
- 如何在一个对话框里显示多结果?
- 紧急求助!如何将java applet中的图片文件和.class文件上载到网页中去???
- Hibernate事务不能跨Servlet?
- Jfreechart:为什么没有standardlegend类
- ssh框架整合问题
像平常一样返回就行了啊
我用servlet写过
页面请求img( <img src='hello.do'></img>)hello.do是你部署好的servlet
然后servlet把数据取出来返回给页面就行了
好像返回之前还要改下返回类型,记不太清了
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;
}