码迷,mamicode.com
首页 > 编程语言 > 详细

javaweb页面上展示动态图片

时间:2016-09-14 16:38:47      阅读:341      评论:0      收藏:0      [点我收藏+]

标签:

HTML

<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页面上展示动态图片

标签:

原文地址:http://www.cnblogs.com/voctrals/p/5872663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!