<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="java.net.HttpURLConnection,java.net.URL"%>
<%@page import="java.io.*" %>
<%
response.reset();
//设置response header
response.addHeader("Content-Disposition","attachment;filename=hello.jpg");
response.setContentType("application/octet-stream");
//response.setContentType("application/application/x-download");
URL url = new URL("http://img.cdeledu.com/FAQ/2015/0611/1434007544046-0.jpg");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream fis = conn.getInputStream();
OutputStream outp = response.getOutputStream();
byte[] b = new byte[1024];
int i = 0;
while ((i = fis.read(b)) > 0) {
outp.write(b, 0, i);
}
outp.flush();
out.clear();
out = pageContext.pushBody();
fis.close();
%>
jsp远程调用资源图片,以附件形式下载
最新推荐文章于 2022-05-30 20:36:52 发布