java 解决图片防盗链

来源:互联网 发布:tomcat启动源码 编辑:程序博客网 时间:2024/06/06 10:42
< %@page contentType="image/jpeg" import="java.io.OutputStream,java.io.InputStream,java.net.URL,java.net.URLConnection" language="java"%>< %
   //response.reset();
   try{
   OutputStream os = response.getOutputStream();
   String picPath = request.getQueryString();
   picPath = picPath.substring(4,picPath.length());
   URLConnection u = new URL(picPath).openConnection();
   InputStream in = u.getInputStream();
   if (null != in) {
   int len;
   byte[] b = new byte[1024];
   while ((len = in.read(b)) != -1) { // 循环读取
   os.write(b, 0, len); // 写入到输出流
   }
   os.flush();
   in.close();
   }
   os.close();
   out.clear();
   out = pageContext.pushBody();
   }catch(Exception e){
   e.printStackTrace();
   }
%>
0 0
原创粉丝点击