码迷,mamicode.com
首页 > Web开发 > 详细

HTTP请求头图片打开

时间:2018-04-17 13:12:27      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:HTTP请求头图片打开

import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; //图片压缩 public class Demo2 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //通知浏览器打开一副图片 response.setHeader("content-type", "image/jpeg"); InputStream is = new FileInputStream(new File("D:/TOOL/MyEclipseSpace/day04/WebRoot/images/cc.jpg")); OutputStream os = response.getOutputStream(); byte[] buf = new byte[1024]; int len = 0; while((len = is.read(buf)) > 0) { os.write(buf,0,len); } is.close(); os.close(); } }

技术分享图片

HTTP请求头图片打开

标签:HTTP请求头图片打开

原文地址:http://blog.51cto.com/357712148/2104337

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