首页 > 编程 > Java > 正文

java 解决图片防盗链

2019-11-08 03:15:55
字体:
来源:转载
供稿:网友
< %@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();   }%>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表