前端jsp:
application.setAttribute("url", arrPic[0]);
<script>
window.service.src = "GetImageFile.jsp";
</script>
GetImageFile.jsp:
<%@ page info="Random Image Show"
pageEncoding="GBK" contentType="image/jpg"
autoFlush="true" buffer="16kb" session="false" import="java.io.*" import="java.net.*"
%>
<%
try
{
System.out.println("ClientUrl=" + (String)application.getAttribute("url"));
String clientUrl = (String)application.getAttribute("url");
URL url = new URL(clientUrl);
URLConnection conn = url.openConnection();
InputStream fis = conn.getInputStream();
ServletOutputStream sos = response.getOutputStream();
int i = fis.available(); // 得到文件大小
byte buf[] = new byte[i];
int len = 0;
while ((len = fis.read(buf)) != -1) {
sos.write(buf, 0, len);
}
sos.flush();
sos.close();
fis.close();
out.clear();
out = pageContext.pushBody();
}
catch (Exception e)
{
e.printStackTrace();
}
%>