首页 > 代码库 > javaweb页面上展示动态图片
javaweb页面上展示动态图片
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页面上展示动态图片
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。