日期:2014-05-19 浏览次数:20704 次
public ActionForward outputBlob(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { DynaBean dynaform = (DynaBean) form; Long attid = Long.valueOf((String) dynaform.get("attid")); DcProjectatt dcProjectatt = dcProjectattMag.getObjectById(attid); String attcontent = dcProjectatt.getAttpath(); try { File file = new File(attcontent); InputStream is = new FileInputStream("D:\\tomcat\\webapps\\ccms\\u\\cms\\www\\201206\\041559429329.xlsx"); @SuppressWarnings("unused") int length = 0; byte[] buf = new byte[1024]; while ((length = is.read(buf)) != -1) { response.getOutputStream().write(buf); } is.close(); } catch (Exception e) { e.printStackTrace(); } return null; }
<td align="left"> <a href="${ctx}/zxsb/dcProjectatt.do?method=outputBlob&attid=${dcProjectatt.attid}" target="_blank"><c:out value="${dcProjectatt.attname}" /> </a> </td>
// 设置response的Header response.addHeader("Content-Disposition", "attachment;filename=" + "041559429329.xlsx"); response.addHeader("Content-Length", "" + file.length()); response.setContentType("application/octet-stream");
------解决方案--------------------