我要从服务器读个图片显示到jsp
jsp页面
<img src="getPic.do">
后台
@RequestMapping(value = "getPic", method = RequestMethod.GET)
public void getPic(HttpServletRequest request,HttpServletResponse response) throws Exception {
response.setContentType("img/png");
response.setCharacterEncoding("utf-8");
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();
String path = servletContext.getRealPath("Wopop_files/1.png");
FileInputStream fis = null;
File file = new File(path);
fis = new FileInputStream(file);
byte[] b = new byte[fis.available()];
fis.read(b);
OutputStream out = response.getOutputStream();
out.write(b);
out.flush();
}
图片没显示,请求之后倒是下载了个getPic.DO文件,咋回事啊。。
汪汪一只猫
相关分类