前端中要显示的是图片,不是URL字符串,来位大神救救我,告诉我应该去学那些也行
网络地址是直接可以在浏览器里访问打开么
1、如果你的路径是http这样直接可以在浏览器显示的用 <img src="http://路径">;
2、如果是war包打包的路径,用相对路径, <img src="../picture/name">;
3、如果没有打war包,也不是可以直接显示的,自己后台写个输出流的方法,之后前台<img src="后台方法访问路径">
类似这样
public void upload( HttpServletResponse response,String name) {
OutputStream os = null;
FileInputStream fis = null;
try {
os = response.getOutputStream();
fis = new FileInputStream("/home/picture/"+name);
byte[] buffer = new byte[1024];
while(fis.read(buffer) != -1) {
os.write(buffer);
}
}catch (Exception e){
}
finally {
if(ValidateUtil.objectIsNotNull(os)){
try {
os.flush();
os.close();
fis.close();
}catch (Exception e){
}
}
}
}
直接后端传过来可以访问的图片url前端使用img src="url"展示