【问题标题】:Fetch Images from Apache Server into Web application hosted on tomcat server从 Apache 服务器获取图像到托管在 tomcat 服务器上的 Web 应用程序
【发布时间】:2021-01-06 14:45:34
【问题描述】:

我已经构建了一个 Spring Boot Web 应用程序。它托管在端口 80 上的 tomcat 服务器上。

为了从服务器动态加载图像,我使用的是 xampp 提供的 apache 服务器。所有图片都在 9090 端口访问。

在我的 Web 应用程序代码中,我在 url 中加载带有 localhost:9090 的图像,如下所示。

<img th:src="@{${'http://localhost:9090/COVID/DD/' + item.imageFileName}}" class="card-img-top rounded-0"  />

问题:由于url路径是localhost,所以我使用服务器的公网ip查看web应用时,图片加载不出来。

如何在不将主机硬编码为localhost 的情况下从端口 9090 获取图像?

【问题讨论】:

    标签: javascript html spring-boot


    【解决方案1】:

    如果我理解正确,您想从同一主机获取图像,但端口不同。

    您可以为此使用 URL API:

    const url = new URL(window.location.origin)
    url.port = 9090
    
    console.log(url)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 2011-12-13
      • 2018-04-09
      • 1970-01-01
      相关资源
      最近更新 更多