gpt4 book ai didi

java - 如何访问存储在服务器上的图像

转载 作者:行者123 更新时间:2023-11-30 04:29:14 24 4
gpt4 key购买 nike

我有一个托管在 jelastic.com 上的 Web 应用程序。我使用路径 /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>

最佳答案

Jelastic 中的主文件夹主要用于存储目的。您最好将文件保存在网络服务器的文件夹中。因此尝试替换您使用的代码:

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>

关于java - 如何访问存储在服务器上的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15070207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com