`
jzj41232216
  • 浏览: 41390 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

用流打开图片

    博客分类:
  • jsp
阅读更多
前端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();  
}  
%>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics