日期:2014-05-18 浏览次数:20872 次
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();
}
file:///C:/123.png
file:///C:/123.doc
@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