javaweb页面上展示动态图片
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javaweb页面上展示动态图片相关的知识,希望对你有一定的参考价值。
<img alt="点击设定" name="CONSTRUCTIONPLANHIS_IMAGE_curr_img_0" src="view/showImage/${image}">
JAVA
import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import com.ajz.util.FileUtil; @Controller @RequestMapping(value = "/view") public class ImageViewController { @RequestMapping("showImage/{pic_name:.+}") public void showImage(HttpServletResponse response, @PathVariable String pic_name) {// pic_addr:图片路径(d:\\upload\a.jpg) response.setContentType("image/*"); FileInputStream fis = null; OutputStream os = null; try { fis = new FileInputStream(FileUtil.getRealPath() + pic_name); os = response.getOutputStream(); int count = 0; byte[] buffer = new byte[1024 * 8]; while ((count = fis.read(buffer)) != -1) { os.write(buffer, 0, count); os.flush(); } } catch (Exception e) { e.printStackTrace(); } finally { try { fis.close(); os.close(); } catch (IOException e) { e.printStackTrace(); } } } }
以上是关于javaweb页面上展示动态图片的主要内容,如果未能解决你的问题,请参考以下文章