这个SpringMVC没什么关系吧,我在jsp中做过一个图片的下载,你可能要修改下代码 response.setContentType("application/x-download"); //application.getRealPath("/main/mvplayer/CapSetup.msi");获取的物理路径 String filedownload = request.getRealPath("/")+"/organization/img/"+"组织架构图.png"; String filedisplay = "组织架构图.png"; filedisplay = URLEncoder.encode(filedisplay,"UTF-8"); response.addHeader("Content-Disposition","attachment;filename=" + filedisplay); java.io.OutputStream outp = null; java.io.FileInputStream in = null; try { outp = response.getOutputStream(); in = new java.io.FileInputStream(filedownload); byte[] b = new byte[1024]; int i = 0; while((i = in.read(b)) > 0) { outp.write(b, 0, i); } outp.flush(); //要加以下两句话,否则会报错 //java.lang.IllegalStateException: getOutputStream() has already been called for this respons out.clear(); out = pageContext.pushBody(); } catch(Exception e) { System.out.println("Error!"); e.printStackTrace(); } finally { if(in != null) { in.close(); in = null; } if(in != null) { in.close(); in = null; } } 这些在网上找也很好找的
81,121
社区成员
341,743
社区内容
加载中
试试用AI创作助手写篇文章吧