服务器读取图片到jsp显示问题 财富值35

2016-09-25 16:10发布

我要从服务器读个图片显示到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文件,咋回事啊。。

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
1条回答

response.setContentType("image/png");

一周热门 更多>