在引用百度空间 网易相册等图片服务器中的图片时遇到图片防盗链。破解方法如下
引用图片的地方改为<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破解图片防盗链 - 李岩的博客