1.jsp页面
<img src="${ctx}/xx/xxxx/testImgUrl">
2.后台
@RequestMapping("/testImgUrl")
public void testImgUrl(HttpServletRequest request,HttpServletResponse response) throws IOException {
//FileInputStream fis = null;
InputStream fis = null;
OutputStream os = null;
URL url = null;
HttpURLConnection httpUrl = null;
try {
url = new URL("http://www.xxxx.cn/img/test.jpg");//远程图片地址
httpUrl = (HttpURLConnection) url.openConnection();
httpUrl.connect();
//fis = new FileInputStream("d:/img/test.jpg");//本地图片地址
fis = httpUrl.getInputStream();
os = response.getOutputStream();
int count = 0;
byte[] buffer = new byte[1024 * 8];
while ((count = fis.read(buffer)) != -1) {
os.write(buffer, 0, count);
os.flush();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fis.close();
os.close();
httpUrl.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
3.上传文件到远程的文件服务器,待续,,,,,,,,,,