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://azwzsj.com/article/pspceg.html