使用ajax将在前台无法显示的图片地址传到后台,转换为流后怎么显示在页面?
地址已传递,且正常转换为流,但是页面还是无法显示Stringpath=request.getParameter("path");URLurl=newURL(path);U...
地址已传递,且正常转换为流,但是页面还是无法显示
String path = request.getParameter("path");
URL url = new URL(path);
URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
ServletOutputStream output = response.getOutputStream();
byte[] tmp = new byte[1024];
int i=0;
while ((i = in.read(tmp)) != -1) {
output.write(tmp, 0, i);
}
in.close();
output.flush(); //强制清出缓冲区
output.close();
// Ajax
response.setContentType("image/jpeg");
response.setHeader("Cathe-Control", "no-cache");
response.setHeader("Pragma", "no-cache"); 展开
String path = request.getParameter("path");
URL url = new URL(path);
URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
ServletOutputStream output = response.getOutputStream();
byte[] tmp = new byte[1024];
int i=0;
while ((i = in.read(tmp)) != -1) {
output.write(tmp, 0, i);
}
in.close();
output.flush(); //强制清出缓冲区
output.close();
// Ajax
response.setContentType("image/jpeg");
response.setHeader("Cathe-Control", "no-cache");
response.setHeader("Pragma", "no-cache"); 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询