前端主要部分
>下载
>下载
服务端
getImg.action实现 主要部分
public String execute() throws Exception {
ServletOutputStream out = null;
String fileServer = “可以访问图片的域名或路径”;
String imgPath = request_.getParameter("path");
try {
//获取图片存放路径
String imgUrl = fileServer + imgPath;
log.info("图片真实路径: "+ imgUrl);
URL url = new URL(imgUrl);
SslUtils.ignoreSsl();
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
InputStream input = conn.getInputStream();//通过输入流获取图片数据
response_.setContentType("multipart/form-data");
out = response_.getOutputStream();
//读取文件流
int len = 0;
byte[] buffer = new byte[1024 * 10];
while ((len = input.read(buffer)) != -1){
out.write(buffer,0,len);
}
out.flush();
}catch (Exception e){
e.printStackTrace();
}finally {
if (out != null) {
out.close();
}
}
return null;
}
struts.xml 配置