您的位置:首页 > 其它

采用URL访问资源,隐藏真实地址

2015-03-28 13:17 295 查看
public void test() throws IOException{

DataInputStream in=null;
DataOutputStream temps=null;
HttpServletResponse response = ServletActionContext.getResponse();
try{
//  out.clear();
//  out = pageContext.pushBody();

// 读到流中
//String strPdfPath = new String("/test/auto_pdf/files/"+gid+"/"+file_name);

String downFileUrl="http://203.86.108.1/summary_traffic_report_web_test/summary_monthly_traffic_report_images_and_html_test/20499/all_sites_traffic_summary_201502.html";

URL downUrl = new URL(downFileUrl);

URLConnection conn = downUrl.openConnection();

System.out.println(conn.getContent());
int dataSize = conn.getContentLength(); //取得要下载的数据的长度
System.out.print("dataSize = " + dataSize);
// 设置输出的格式
response.reset();
response.setContentType("text/html");  // 如果是图片 则写成 response.setContentType("image/jpeg")

temps = new DataOutputStream(response.getOutputStream());
in = new DataInputStream(conn.getInputStream());

byte[] b = new byte[2048];
int i = 0;
while ((i = in.read(b)) > 0) {
temps.write(b,0,i);
temps.flush();
}

}catch(Exception e){
e.printStackTrace();
}finally{
if(in!=null)in.close();
if(temps!=null)temps.close();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: