springMVC下的通过<img src="">标签的src访问图片
2016-12-05 18:10
344 查看
图片的回显,在src中放入图片的回显路径
/**
* 百度ueditor编辑器的图片回显 通过<img/>标签中的src访问 例:http://localhost:8080/qxzst-sp-apis//pc/image/getUeditorImg/1480504795791062668/png
* @param imgname 图片名
* @param imgType 扩展名
* @param response
*/
@RequestMapping(value = "getUeditorImg/{imgname}/{imgType}", method = RequestMethod.GET)
public void getUeditorImg(@PathVariable String imgname, @PathVariable String imgType,
HttpServletResponse response) {
if ("null".equals(imgname) || "null".equals(imgType) || StringUtils.isBlank(imgname)
|| StringUtils.isNotBlank(imgType)) {
return;
}
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
String timeStr = imgname.substring(0, imgname.length() - 6);
String dateFile = df.format(new Date(Long.parseLong(timeStr)));
File file = new File(UEDITOR_IMG_PATH + "/" + dateFile + "/" + imgname + "." + imgType);
in = new BufferedInputStream(new FileInputStream(file));
out = new BufferedOutputStream(response.getOutputStream());
response.setContentType(new MimetypesFileTypeMap().getContentType(file));// 设置response内容的类型
response.setHeader("Content-disposition", "attachment;filename=" + imgname + "." + imgType);// 设置头部信息
byte[] buffer = new byte[10240];
int length = 0;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
out.flush();
} catch (IOException e) {
getLogger().error(e.getMessage(), e);
writeError500(response, e);
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 百度ueditor编辑器的图片回显 通过<img/>标签中的src访问 例:http://localhost:8080/qxzst-sp-apis//pc/image/getUeditorImg/1480504795791062668/png
* @param imgname 图片名
* @param imgType 扩展名
* @param response
*/
@RequestMapping(value = "getUeditorImg/{imgname}/{imgType}", method = RequestMethod.GET)
public void getUeditorImg(@PathVariable String imgname, @PathVariable String imgType,
HttpServletResponse response) {
if ("null".equals(imgname) || "null".equals(imgType) || StringUtils.isBlank(imgname)
|| StringUtils.isNotBlank(imgType)) {
return;
}
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
String timeStr = imgname.substring(0, imgname.length() - 6);
String dateFile = df.format(new Date(Long.parseLong(timeStr)));
File file = new File(UEDITOR_IMG_PATH + "/" + dateFile + "/" + imgname + "." + imgType);
in = new BufferedInputStream(new FileInputStream(file));
out = new BufferedOutputStream(response.getOutputStream());
response.setContentType(new MimetypesFileTypeMap().getContentType(file));// 设置response内容的类型
response.setHeader("Content-disposition", "attachment;filename=" + imgname + "." + imgType);// 设置头部信息
byte[] buffer = new byte[10240];
int length = 0;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
out.flush();
} catch (IOException e) {
getLogger().error(e.getMessage(), e);
writeError500(response, e);
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
相关文章推荐
- [转]springMVC下的通过<img src="">标签的src访问图片
- <img src="">标签通过js异步加载图片
- 解决用<img src="<%# Eval("ShowPhoto")%>"动态绑定图片,发布到IIS上无法显示的问题
- <img src="">标签中的src 找不到 Servlet的路径
- 在html的<img src="">中调用js的函数或者js变量来指定图片路径
- <img src="">中放绝对路径或者不在项目下图片的方法
- html <img>标签 src=""内的图片路径问题
- <img src="http://localhost:8080/ssmy/upload/${uploadFile }" alt="sss"/>显示图片
- <img src="">战胜<asp:Image>
- <img src=""> img标签的src为空的缺陷
- 诡异的【session丢失】和无语的【&lt;img src=""&gt;标签】
- asp.net webform 中怎样写二进制形式的<img src="" />形式
- 正则匹配<img src="xxxxxx" alt="" />标签的相关写法
- 按钮图片<input type="image" class="peidui_Bt1" src="img/pedui_bt.png" />
- 前端的一些注意事项 <img onerror="src='images/no.png'">标签引起的异常
- 诡异的【session丢失】和无语的【<img src="">标签】
- 通过CSS使得<img>标签变灰,从而图片看起来变灰
- dede调用img图片src地址<img src="[field:litpic/]">
- <img src=""/>引发的问题
- springMVC配置静态资源访问的<mvc:resources>标签的使用