您的位置:首页 > Web前端 > JavaScript

Jsp破解图片防盗链

2013-12-26 17:18 405 查看
在引用百度空间 网易相册等图片服务器中的图片时遇到图片防盗链。破解方法如下

引用图片的地方改为<img src="http://<%=request.getLocalAddr()%>:<%=request.getLocalPort()%><%=request.getContextPath()%>/url.jsp?url='+ 图片路径 +'" width="100" height="100" />

保存下面的代码 例如url.jsp

<%@ 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();

}

%>

http://liyanblog.cn/articles/2012/12/29/1356779047456.html
版权所有 转载请注明出处:Jsp破解图片防盗链
- 李岩的博客
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息