java如何访问存储在服务器上的映像
我有一个web应用程序托管在jelastic上。通用域名格式。我使用路径/opt/glassfish3/temp
将一个映像上载到服务器的主目录中。代码如下:
FileOutputStream fos = new FileOutputStream("/opt/glassfish3/temp/" + fileName);
fos.write(uploadedFile.getContents());
fos.flush();
fos.close();
我使用图像标签来显示图像文件,但它给了我一个损坏的图像。html代码如下所示:
<img src="/opt/glassfish3/temp/${sessionScope['userdet']['image']}" width="200px" ></img>
# 1 楼答案
Jelastic中的主文件夹主要用于存储目的。您最好将文件保存在web服务器的文件夹中。 因此,请尝试替换您使用的代码:
FileOutputStream fos = new FileOutputStream("/opt/glassfish3/temp/" + fileName)
关于这一点:
FileOutputStream fos = new FileOutputStream("/opt/glassfish3/glassfish/domains/ domain1/applications/{PUT_HERE_CONTEXT_NAME}/" + fileName);
然后修改html代码:
<img src="/opt/glassfish3/temp/${sessionScope['userdet']['image']}" width="200px" ></img> -> <img src="${sessionScope['userdet']['image']}" width="200px" ></img>