java - jsp中无法访问jpg

标签 java image apache jsp

我的webcontent/images文件夹中有两个图像文件the_logo.jpglogo.png

能够访问 .png 文件

<img alt="Powerpay1" src="./images/logo.png"  width="250" height="50" />

但是无法访问.jpg文件

<img alt="Powerpay" src="./images/the_logo.jpg"  width="250" height="50" />

我该如何解决这个问题? 如果需要任何其他信息,请随时询问。

注意:我使用的是 Apache tomcat。

最佳答案

使用

<img alt="Powerpay1" src="../images/logo.png"  width="250" height="50" />

<img alt="Powerpay1" src="../images/the_logo.jpg"  width="250" height="50" />

This code will take the cursor to the previous folder.

If you have two nested folder, use ../../ or three nested folders, use ../../../and so on to go to the root of the directory and browse respectly.

而不是

<img alt="Powerpay1" src="./images/logo.png"  width="250" height="50" />

<img alt="Powerpay1" src="./images/the_logo.jpg"  width="250" height="50" />
<小时/>

使用 scriptlet 来实现此目的的另一种最佳方法

例如:

<%
    String base = request.getContextPath() + "/";
    if (base == null || base.isEmpty()) {
        base = "/";
    }
%>

<img alt="Powerpay1" src="<%=base%>images/logo.png"  width="250" height="50" />

关于java - jsp中无法访问jpg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45276798/

相关文章:

python - Google 图片 APIexecute_transforms() 返回 "there has been an error"

php - crontab 内存不足

linux - Apache 虚拟主机无法在 Ubuntu 14.04 LTS 上运行

apache - 反向代理和 getServerPort() 背后的 WebSphere Portal

java - ImageMagick 命令缓慢问题

java - 以编程方式关闭 jetty 客户端

php - 如何在一天中的不同时间使用不同的背景图像

java - 当我进行 Rest api 调用时,使用 SpringBoot 动态创建列/表

java - MySQL数据库不写入

css:浏览器缩放时图像出现问题