日期:2014-05-18  浏览次数:20814 次

关于SpringMVC下载不弹窗的问题,谢谢。
关于SpringMVC下载不弹窗的问题,谢谢。

代码如下:




response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition", "attachment;fileName="
+ new String(fileName.getBytes("gb2312"), "iso8859-1"));


String filePath =//这里是可以取到真实的物理地址的 
类似D:\tomcat\tmp123.doc 这样的路径
InputStream in = new FileInputStream(filePath);

OutputStream os = response.getOutputStream();

byte[] b = new byte[1024 * 1024];
int length;
while ((length = in.read(b)) > 0) {
os.write(b, 0, length);
}
in.close();
}



代码不报错,就是不弹出下载框,请问是为啥呢?谢谢。
还有,我直接把图片文件的地址(单击图片文件名之后,把数据库中存储的真实地址赋值给一个<img> 标签) 也显示不了。右键查看图片的属性,显示的是 

file:///C:/123.png

file:///C:/123.doc


之类的地址。 

------解决方案--------------------
jQuery的ajax函数、及ajaxSubmit等函数的返回类型(dataType)只有xml、text、json、html等类型,没有“流”类型.

所以你只能这样写个请求:
window.location.href = path+'/phoneInfo/downloadTemplate.do';
------解决方案--------------------
引用:
请问一下,为什么图片不行呢,谢谢。给图片赋值的时候,出不来。

response.setContentType("multipart/form-data");
最好写MimeType属性,如果要浏览器在线开必须这么做;
multipart/form-data用于二进制六下载使用
------解决方案--------------------
恩,这个是前端穿了个id过来,然后我从word中将图片读出来,根据id,返回具体的那张图片给页面展示

@RequestMapping("/image")
    @ResponseBody
    public String getImagePath(HttpServletRequest request,HttpServletResponse response) {
String filePath = null;
try {
filePath = new String((request.getParameter("filePath")).getBytes("iso-8859-1"),"utf-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
return null;
}

String idx = request.getParameter("id");
if (filePath == null 
------解决方案--------------------
 idx == null) {
return null;
}

response.setContentType("image/jpeg");
int index = Integer.parseInt(idx);
try {
ServletOutputStream out = response.getOutputStream();
WordDocUtil wdu = new WordDocUtil(filePath);
List<byte[]> imageCache = wdu.getAllDocPicture();
if (imageCach